sensebot

package
v0.0.0-...-b10a33c Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2025 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmojiX         = "❌"
	EmojiHOURGLASS = "⏳"
	EmojiTICK      = "✅"
	EmojiGLOBE     = "🌐"
)
View Source
const UnixSecondsMax = 253402300799

Variables

View Source
var (
	HistoryStrings = map[event.HistoryVisibility]string{
		event.HistoryVisibilityWorldReadable: "World readable",
		event.HistoryVisibilityShared:        "Available to all members",
		event.HistoryVisibilityInvited:       "Available to members only after they are invited",
		event.HistoryVisibilityJoined:        "Available to members only after they join",
	}
	JoinRuleStrings = map[event.JoinRule]string{
		event.JoinRulePublic:          "Public to anyone who knows the link",
		event.JoinRuleInvite:          "Invite only",
		event.JoinRuleKnock:           "Users must request to join",
		event.JoinRuleRestricted:      "Must be a member of another room or space in order to join",
		event.JoinRuleKnockRestricted: "Can request to join if user is already a member of another room or space",
		event.JoinRulePrivate:         "Uh oh",
	}
	GuestAccessStrings = map[event.GuestAccess]string{
		event.GuestAccessCanJoin:   "Guests can join",
		event.GuestAccessForbidden: "Guests cannot join",
	}
)
View Source
var StateStickerPack = event.Type{Type: "im.ponies.room_emotes", Class: event.StateEventType}

Functions

func AppendStickerCommand

func AppendStickerCommand(ctx *CommandContext) error

func ContactServer

func ContactServer(c chan ServerResult, bot *Client, ctx context.Context, serverName string, timeout time.Duration, sem *semaphore.Weighted)

func FetchStateHistory

func FetchStateHistory(ctx context.Context, bot *Client, roomID id.RoomID, eventID id.EventID, result []*event.Event) []*event.Event

func ForwardEvent

func ForwardEvent(ctx *CommandContext) error

func GetEventCallback

func GetEventCallback(ctx *CommandContext) error

func GetMembershipHistoryCallback

func GetMembershipHistoryCallback(ctx *CommandContext) error

func GetServersCallback

func GetServersCallback(ctx *CommandContext) error

func GetStateContent

func GetStateContent(ctx context.Context, room *mautrix.Room, eventType event.Type) *event.Content

func GetStateEventCallback

func GetStateEventCallback(ctx *CommandContext) error

func GetStateHistoryCallback

func GetStateHistoryCallback(ctx *CommandContext) error

func HelpCommandCallback

func HelpCommandCallback(ctx *CommandContext) error

func IDPillConverter

func IDPillConverter(_, mxid, eventID string, _ format.Context) string

func JoinCommandCallback

func JoinCommandCallback(ctx *CommandContext) error

func LeaveCommandCallback

func LeaveCommandCallback(ctx *CommandContext) error

func ParseMatrixReference

func ParseMatrixReference(target string) id.MatrixURI

func PingCommandCallback

func PingCommandCallback(ctx *CommandContext) (err error)

func ProgressBar

func ProgressBar(total, current, length int) string

func ResolveAliasCommandCallback

func ResolveAliasCommandCallback(ctx *CommandContext) error

func RoomIDFromReference

func RoomIDFromReference(ctx context.Context, bot *Client, target id.MatrixURI) id.RoomID

func RoomInfoCommandCallback

func RoomInfoCommandCallback(ctx *CommandContext) error

func ServerInfoCommandCallback

func ServerInfoCommandCallback(ctx *CommandContext) error

func TimestampToDatetimeCallback

func TimestampToDatetimeCallback(ctx *CommandContext) error

func UserInfoCommandCallback

func UserInfoCommandCallback(ctx *CommandContext) error

func UsersOfCallback

func UsersOfCallback(ctx *CommandContext) error

Types

type Client

type Client struct {
	Mau                    mautrix.Client
	Fed                    *federation.Client
	DB                     db.Manager
	Config                 Config
	MainContext            context.Context
	Commands               []Command
	StartedAt              time.Time
	Crypto                 *cryptohelper.CryptoHelper
	ObservatoryClient      *observatory.ObservatoryClient
	PolicyManager          *policyeval.PolicyListManager
	Rooms                  map[id.RoomID]*mautrix.Room
	GenericPolicyEvaluator *policyeval.PolicyListManager

	DidVerify bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, config Config) (c *Client, err error)

func (*Client) AddCommand

func (bot *Client) AddCommand(command Command) error

AddCommand adds a command to the internal register. The command must not have a conflicting name or alias.

func (*Client) AddReaction

func (bot *Client) AddReaction(room id.RoomID, evt id.EventID, key string) error

AddReaction adds a reaction to an event.

func (*Client) AddReactionBG

func (bot *Client) AddReactionBG(ctx context.Context, room id.RoomID, evt id.EventID, key string)

AddReactionBG unlike AddReaction, runs the AddReaction function in a separate goroutine, ignoring any errors.

func (*Client) AddStatus

func (bot *Client) AddStatus(ctx context.Context, roomID id.RoomID, evt id.EventID, key string, key2 *string) chan bool

func (*Client) FetchUsers

func (bot *Client) FetchUsers(ctx context.Context, room id.RoomID, filter func(id.UserID, *event.MemberEventContent) bool) (map[id.UserID]*event.MemberEventContent, error)

func (*Client) GetCommand

func (bot *Client) GetCommand(name string) Command

GetCommand gets a registered command from the sensebot client. A case-sensitive comparison is performed so name should be lowercased before calling.

func (*Client) GetStringBan

func (bot *Client) GetStringBan(list *policyeval.PolicyList, target string) *event.Event

func (*Client) HandlePanic

func (bot *Client) HandlePanic(ctx context.Context, evt *event.Event)

func (*Client) LoadRooms

func (bot *Client) LoadRooms(ctx context.Context) error

func (*Client) OnReaction

func (bot *Client) OnReaction(ctx context.Context, evt *event.Event)

func (*Client) ProcessMessage

func (bot *Client) ProcessMessage(ctx context.Context, evt *event.Event)

ProcessMessage processes a message event. This function, and NewClient, can only be read if "Order" by "Heaven Pierce Her" is playing.

func (*Client) RemoveCommand

func (bot *Client) RemoveCommand(name string) (cmd Command, err error)

RemoveCommand removes a command.

func (*Client) SendAlert

func (bot *Client) SendAlert(ctx context.Context, content string)

func (*Client) SetVersion

func (bot *Client) SetVersion(v string)

func (*Client) ToRoomID

func (bot *Client) ToRoomID(value string) (id.RoomID, error)

func (*Client) UpdateObservations

func (bot *Client) UpdateObservations(user id.UserID, timestamp int64)

func (*Client) VerifyWithRecoveryKey

func (bot *Client) VerifyWithRecoveryKey(ctx context.Context, recoveryKey string) error

func (*Client) Version

func (bot *Client) Version() string

type Command

type Command struct {
	Name             string
	Usage            string
	Aliases          []string
	ShortDescription string
	LongDescription  string
	Hidden           bool
	Callback         func(ctx *CommandContext) error
}

func (*Command) NewContext

func (cmd *Command) NewContext(client *Client, evt *event.Event, ctx context.Context, args []string) CommandContext

type CommandContext

type CommandContext struct {
	InvokedCommand *Command
	Bot            *Client
	Event          *event.Event
	Context        context.Context
	Args           []string
	RuntimeID      string // Unique ID for the command execution, used for logging and debugging
	ExecStart      time.Time
}

func (*CommandContext) Logger

func (ctx *CommandContext) Logger() *zerolog.Logger

func (*CommandContext) PrepareReply

func (ctx *CommandContext) PrepareReply(msg string, msgtype event.MessageType) event.MessageEventContent

func (*CommandContext) Reply

func (ctx *CommandContext) Reply(msg string, msgtype event.MessageType) (*mautrix.RespSendEvent, error)

func (*CommandContext) ShouldReplyNotice

func (ctx *CommandContext) ShouldReplyNotice(msg string) error

type Config

type Config struct {
	DatabaseFile  string             `json:"database_file"`
	HomeserverURL string             `json:"homeserver_url"`
	AccessToken   string             `json:"access_token"`
	Prefix        string             `json:"prefix"`
	PickleKey     string             `json:"pickle_key"`
	StoreFile     string             `json:"store_file"`
	OwnerIDs      []id.UserID        `json:"owner_ids"`
	AutoJoinAll   bool               `json:"auto_join_all"`
	RejectInvites bool               `json:"reject_invites"`
	RejectReason  string             `json:"reject_reason"`
	AlertRoom     id.RoomID          `json:"alert_room_id"`
	RecoveryKey   string             `json:"recovery_key"`
	Observatory   ObservatoryConfig  `json:"observatory"`
	PolicyRooms   []id.RoomID        `json:"policy_rooms"`
	Logging       *zeroconfig.Config `json:"logging"`
}

func LoadConfig

func LoadConfig(location string) (config *Config, err error)

LoadConfig attempts to the l

func (*Config) IsValid

func (c *Config) IsValid() bool

IsValid checks if the config is valid and completed enough to at least log in and run a command

type MSC3946DynamicPredecessorEventContent

type MSC3946DynamicPredecessorEventContent struct {
	PredecessorRoomID id.RoomID `json:"predecessor_room_id"`
	ViaServers        []string  `json:"via_servers"`
}

type MaubotPingResponse

type MaubotPingResponse struct {
	*event.MessageEventContent
	Pong      pong           `json:"pong"`
	RelatesTo *pongRelatesTo `json:"m.relates_to"`
}

type MaybeResult

type MaybeResult[T any] struct {
	Value T
	Error error
}

func (*MaybeResult[T]) IsError

func (m *MaybeResult[T]) IsError() bool

func (*MaybeResult[T]) IsOk

func (m *MaybeResult[T]) IsOk() bool

func (*MaybeResult[T]) MustValue

func (m *MaybeResult[T]) MustValue() T

type ObservatoryConfig

type ObservatoryConfig struct {
	BaseURL      string `json:"base_url"`
	SharedSecret string `json:"shared_secret"`
}

type RoomInfo

type RoomInfo struct {
	*mautrix.Room
	DynamicPredecessor MSC3946DynamicPredecessorEventContent
	Name               event.RoomNameEventContent
	ID                 id.RoomID
	CanonicalAlias     event.CanonicalAliasEventContent
	CreateEvent        event.CreateEventContent
	Tombstone          event.TombstoneEventContent
	Members            map[id.UserID]*event.MemberEventContent
	Encryption         event.EncryptionEventContent
	JoinRules          event.JoinRulesEventContent
	GuestAccess        event.GuestAccessEventContent
	HistoryVisibility  event.HistoryVisibilityEventContent
	Topic              event.TopicEventContent
	Avatar             event.RoomAvatarEventContent
	// contains filtered or unexported fields
}

func GetFullRoomInfo

func GetFullRoomInfo(ctx context.Context, bot Client, roomID id.RoomID) RoomInfo

func ManualMutualRooms

func ManualMutualRooms(ctx *CommandContext, target id.UserID) []RoomInfo

func RoomInfoFromState

func RoomInfoFromState(ctx context.Context, bot Client, roomID id.RoomID, state mautrix.RoomStateMap) RoomInfo

func (*RoomInfo) CalculatedName

func (room *RoomInfo) CalculatedName() string

func (*RoomInfo) GetHeroes

func (room *RoomInfo) GetHeroes() (heroes []id.UserID)

func (*RoomInfo) Pill

func (room *RoomInfo) Pill() string

func (*RoomInfo) String

func (room *RoomInfo) String() string

func (*RoomInfo) URI

func (room *RoomInfo) URI() *id.MatrixURI

type ServerInfo

type ServerInfo struct {
	Name                 string
	C2S                  MaybeResult[url.URL]
	S2S                  MaybeResult[federation.ResolvedServerName]
	Version              MaybeResult[federation.RespServerVersion]
	Support              MaybeResult[WellKnownSupport]
	RegFlows             []mautrix.UIAFlow
	RegEnabled           bool
	RegError             error
	ExternalAuthProvider *string
	FirstSeen            time.Time
	LastSeen             time.Time
	ObservedUsers        int
}

type ServerResult

type ServerResult struct {
	Homeserver string
	Software   string
	Version    string
	Users      int
	FirstSeen  int64
	LastSeen   int64
	Errors     []error
}

type StickerEventContent

type StickerEventContent struct {
	Images map[string]StickerPackImage `json:"images"`
	Pack   StickerPack                 `json:"pack"`
}

type StickerPack

type StickerPack struct {
	DisplayName string              `json:"display_name,omitempty"`
	AvatarUri   id.ContentURIString `json:"avatar_uri,omitempty"`
	Usage       []string            `json:"usage,omitempty"`
	Attribution string              `json:"attribution,omitempty"`
}

type StickerPackImage

type StickerPackImage struct {
	Url   id.ContentURIString `json:"url"`
	Body  string              `json:"body,omitempty"`
	Info  *event.FileInfo     `json:"info,omitempty"`
	Usage []string            `json:"usage,omitempty"`
}

type UnstableAuthMetadata

type UnstableAuthMetadata struct {
	Issuer                        string   `json:"issuer"`
	AuthorizationEndpoint         string   `json:"authorization_endpoint"`
	TokenEndpoint                 string   `json:"token_endpoint"`
	RegistrationEndpoint          string   `json:"registration_endpoint"`
	RevocationEndpoint            string   `json:"revocation_endpoint"`
	ResponseTypesSupported        []string `json:"response_types_supported"`
	GrantTypesSupported           []string `json:"grant_types_supported"`
	ResponseModesSupported        []string `json:"response_modes_supported"`
	CodeChallengeMethodsSupported []string `json:"code_challenge_methods_supported"`
}

UnstableAuthMetadata from https://github.com/sandhose/matrix-spec-proposals/blob/msc/sandhose/oidc-discovery/proposals/2965-auth-metadata.md

type WellKnownSupport

type WellKnownSupport struct {
	Contacts    []WellKnownSupportContact
	SupportPage *url.URL
}

func (*WellKnownSupport) UnmarshalJSON

func (w *WellKnownSupport) UnmarshalJSON(data []byte) error

type WellKnownSupportContact

type WellKnownSupportContact struct {
	Email            string    `json:"email_address,omitempty"`
	MatrixID         id.UserID `json:"matrix_id,omitempty"`
	UnstableJabberID string    `json:"jabber_id,omitempty"`
	Role             string    `json:"role,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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