policyeval

package
v0.0.0-...-1a3e427 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrAntiSpam

type ErrAntiSpam struct {
	Response *http.Response
	Err      *RespAntiSpam
}

func (*ErrAntiSpam) Error

func (e *ErrAntiSpam) Error() string

type MeowlnirConfig

type MeowlnirConfig struct {
	BaseURL        string    `json:"base_url" yaml:"base_url"`
	ManagementRoom id.RoomID `json:"management_room" yaml:"management_room"`
	AntiSpamSecret string    `json:"anti_spam_secret" yaml:"anti_spam_secret"`
	DummyUser      id.UserID `json:"dummy_user" yaml:"dummy_user"`
	FallbackPE     bool      `json:"fallback_to_internal" yaml:"fallback_to_internal"`
	ServerName     string    `json:"server_name" yaml:"server_name"`
}

type MeowlnirManager

type MeowlnirManager struct {
	Config *MeowlnirConfig
	Client *mautrix.Client
}

func NewMeowlnirManager

func NewMeowlnirManager(config *MeowlnirConfig, client *mautrix.Client) *MeowlnirManager

func (*MeowlnirManager) EventIsPermitted

func (m *MeowlnirManager) EventIsPermitted(_ *event.Event) PermittedResult

func (*MeowlnirManager) InviteIsPermitted

func (m *MeowlnirManager) InviteIsPermitted(inviter id.UserID, invitee id.UserID, roomID id.RoomID) PermittedResult

func (*MeowlnirManager) JoinIsPermitted

func (m *MeowlnirManager) JoinIsPermitted(_ id.UserID, _ id.RoomID) PermittedResult

type PermittedResult

type PermittedResult struct {
	Permitted bool
	Reason    string
	Err       error
	Policy    *event.ModPolicyContent
}

func (*PermittedResult) Error

func (p *PermittedResult) Error() string

func (*PermittedResult) String

func (p *PermittedResult) String() string

type PolicyEvaluator

type PolicyEvaluator interface {
	InviteIsPermitted(id.UserID, id.UserID, id.RoomID) PermittedResult
	JoinIsPermitted(id.UserID, id.RoomID) PermittedResult
	EventIsPermitted(evt *event.Event) PermittedResult
}

PolicyEvaluator represents a generic interface for policy checkers to run against.

type PolicyList

type PolicyList struct {
	*mautrix.Room
	// contains filtered or unexported fields
}

PolicyList represents a policy list room.

func NewPolicyList

func NewPolicyList(ctx context.Context, client *mautrix.Client, room *mautrix.Room) *PolicyList

NewPolicyList creates a new PolicyList instance.

func (*PolicyList) GetAnyBan

func (p *PolicyList) GetAnyBan(userID id.UserID, roomID id.RoomID) *event.ModPolicyContent

GetAnyBan retrieves any ban policy for the given targets. This checks: the sender, the room, the sender's homeserver, the room's origin server Returns the first found policy, or nil if there are no relevant ones.

func (*PolicyList) GetBan

func (p *PolicyList) GetBan(target string, evtType event.Type) *event.Event

GetBan retries the policy state event for a given target and event type.

func (*PolicyList) GetRoomBan

func (p *PolicyList) GetRoomBan(roomID id.RoomID) *event.ModPolicyContent

GetRoomBan retrieves the room ban policy for a given room ID. Returns nil if not found. Checks both m.ban and m.takedown.

func (*PolicyList) GetServerBan

func (p *PolicyList) GetServerBan(serverName string) *event.ModPolicyContent

GetServerBan retrieves the server ban policy for a given server name. Returns nil if not found. Checks both m.ban and m.takedown.

func (*PolicyList) GetUserBan

func (p *PolicyList) GetUserBan(userID id.UserID) *event.ModPolicyContent

GetUserBan retrieves the user ban policy for a given user ID. Returns nil if not found. Checks both m.ban and m.takedown.

func (*PolicyList) GlobRuleMatches

func (p *PolicyList) GlobRuleMatches(entity string) *event.ModPolicyContent

GlobRuleMatches checks if any glob rule in the current list matches the entity.

type PolicyListManager

type PolicyListManager struct {
	// PolicyLists is a map of room IDs to their policy lists.
	PolicyLists map[id.RoomID]*PolicyList
	// RawMapping is a map of arbitrary strings (either an ID or alias) to a room ID.
	RawMapping map[string]id.RoomID
}

PolicyListManager is a manager that manages policy lists, with some higher level functions.

func NewPolicyListManager

func NewPolicyListManager() *PolicyListManager

NewPolicyListManager creates a new, empty PolicyListManager.

func (*PolicyListManager) EventIsPermitted

func (pm *PolicyListManager) EventIsPermitted(evt *event.Event) PermittedResult

EventIsPermitted checks if the event would be blocked by any policy rules Useful to, for example, implicitly ignore banned users.

func (*PolicyListManager) InviteIsPermitted

func (pm *PolicyListManager) InviteIsPermitted(inviter id.UserID, _ id.UserID, roomID id.RoomID) PermittedResult

InviteIsPermitted checks if the inviter is allowed to invite the target to the room.

func (*PolicyListManager) JoinIsPermitted

func (pm *PolicyListManager) JoinIsPermitted(userID id.UserID, roomID id.RoomID) PermittedResult

JoinIsPermitted checks if the user is allowed to join the room.

func (*PolicyListManager) StateHook

func (pm *PolicyListManager) StateHook(wrap func(ctx context.Context, evt *event.Event)) func(ctx context.Context, evt *event.Event)

StateHook will tap into mautrix.Client.OnEvent and update the policy lists in this manager.

type ReqAntiSpam

type ReqAntiSpam struct {
	Inviter id.UserID `json:"inviter"`
	Invitee id.UserID `json:"invitee"`
	RoomID  id.RoomID `json:"room_id"`
}

type RespAntiSpam

type RespAntiSpam struct {
	ErrCode      string `json:"errcode"`
	ErrorMessage string `json:"error"`
}

func (*RespAntiSpam) String

func (r *RespAntiSpam) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL