commands

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2023 License: MPL-2.0 Imports: 15 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Deprecated: this should be used as a placeholder that needs to be fixed
	HelpSectionUnclassified = HelpSection{"Unclassified", -1}

	HelpSectionGeneral = HelpSection{"General", 0}
	HelpSectionAuth    = HelpSection{"Authentication", 10}
	HelpSectionAdmin   = HelpSection{"Administration", 50}
)
View Source
var CommandCancel = &FullHandler{
	Func: func(ce *Event) {
		commandingUser, ok := ce.User.(CommandingUser)
		if !ok {
			ce.Reply("This bridge does not implement cancelable commands")
			return
		}
		state := commandingUser.GetCommandState()

		if state != nil {
			action := state.Action
			if action == "" {
				action = "Unknown action"
			}
			commandingUser.SetCommandState(nil)
			ce.Reply("%s cancelled.", action)
		} else {
			ce.Reply("No ongoing command.")
		}
	},
	Name: "cancel",
	Help: HelpMeta{
		Section:     HelpSectionGeneral,
		Description: "Cancel an ongoing action.",
	},
}
View Source
var CommandDiscardMegolmSession = &FullHandler{
	Func: func(ce *Event) {
		if ce.Bridge.Crypto == nil {
			ce.Reply("This bridge instance doesn't have end-to-bridge encryption enabled")
		} else {
			ce.Bridge.Crypto.ResetSession(ce.RoomID)
			ce.Reply("Successfully reset Megolm session in this room. New decryption keys will be shared the next time a message is sent from the remote network.")
		}
	},
	Name:    "discard-megolm-session",
	Aliases: []string{"discard-session"},
	Help: HelpMeta{
		Section:     HelpSectionAdmin,
		Description: "Discard the Megolm session in the room",
	},
	RequiresAdmin: true,
}
View Source
var CommandHelp = &FullHandler{
	Func: func(ce *Event) {
		ce.Reply(FormatHelp(ce))
	},
	Name: "help",
	Help: HelpMeta{
		Section:     HelpSectionGeneral,
		Description: "Show this help message.",
	},
}
View Source
var CommandLoginMatrix = &FullHandler{
	Func: fnLoginMatrix,
	Name: "login-matrix",
	Help: HelpMeta{
		Section:     HelpSectionAuth,
		Description: "Enable double puppeting.",
		Args:        "<_access token_>",
	},
	RequiresLogin: true,
}
View Source
var CommandLogoutMatrix = &FullHandler{
	Func: fnLogoutMatrix,
	Name: "logout-matrix",
	Help: HelpMeta{
		Section:     HelpSectionAuth,
		Description: "Disable double puppeting.",
	},
	RequiresLogin: true,
}
View Source
var CommandPingMatrix = &FullHandler{
	Func: fnPingMatrix,
	Name: "ping-matrix",
	Help: HelpMeta{
		Section:     HelpSectionAuth,
		Description: "Ping the Matrix server with the double puppet.",
	},
	RequiresLogin: true,
}
View Source
var CommandSetPowerLevel = &FullHandler{
	Func:    fnSetPowerLevel,
	Name:    "set-pl",
	Aliases: []string{"set-power-level"},
	Help: HelpMeta{
		Section:     HelpSectionAdmin,
		Description: "Change the power level in a portal room.",
		Args:        "[_user ID_] <_power level_>",
	},
	RequiresAdmin:  true,
	RequiresPortal: true,
}
View Source
var CommandVersion = &FullHandler{
	Func: func(ce *Event) {
		ce.Reply("[%s](%s) %s (%s)", ce.Bridge.Name, ce.Bridge.URL, ce.Bridge.LinkifiedVersion, ce.Bridge.BuildTime)
	},
	Name: "version",
	Help: HelpMeta{
		Section:     HelpSectionGeneral,
		Description: "Get the bridge version.",
	},
}

Functions

func FormatHelp

func FormatHelp(ce *Event) string

Types

type AliasedHandler

type AliasedHandler interface {
	Handler
	GetAliases() []string
}

type CommandState

type CommandState struct {
	Next   MinimalHandler
	Action string
	Meta   interface{}
}

type CommandingUser

type CommandingUser interface {
	bridge.User
	GetCommandState() *CommandState
	SetCommandState(*CommandState)
}

type Event

type Event struct {
	Bot       *appservice.IntentAPI
	Bridge    *bridge.Bridge
	Portal    bridge.Portal
	Processor *Processor
	Handler   MinimalHandler
	RoomID    id.RoomID
	EventID   id.EventID
	User      bridge.User
	Command   string
	Args      []string
	RawArgs   string
	ReplyTo   id.EventID
	ZLog      *zerolog.Logger
	// Deprecated: switch to ZLog
	Log maulogger.Logger
}

Event stores all data which might be used to handle commands

func (*Event) MainIntent

func (ce *Event) MainIntent() *appservice.IntentAPI

MainIntent returns the intent to use when replying to the command.

It prefers the bridge bot, but falls back to the other user in DMs if the bridge bot is not present.

func (*Event) MarkRead

func (ce *Event) MarkRead()

MarkRead marks the command event as read.

func (*Event) React

func (ce *Event) React(key string)

React sends a reaction to the command.

func (*Event) Redact added in v0.12.2

func (ce *Event) Redact(req ...mautrix.ReqRedact)

Redact redacts the command.

func (*Event) Reply

func (ce *Event) Reply(msg string, args ...interface{})

Reply sends a reply to command as notice, with optional string formatting and automatic $cmdprefix replacement.

func (*Event) ReplyAdvanced added in v0.14.0

func (ce *Event) ReplyAdvanced(msg string, allowMarkdown, allowHTML bool)

ReplyAdvanced sends a reply to command as notice. It allows using HTML and disabling markdown, but doesn't have built-in string formatting.

type FullHandler

type FullHandler struct {
	Func func(*Event)

	Name    string
	Aliases []string
	Help    HelpMeta

	RequiresAdmin  bool
	RequiresPortal bool
	RequiresLogin  bool

	RequiresEventLevel event.Type
}

func (*FullHandler) GetAliases

func (fh *FullHandler) GetAliases() []string

func (*FullHandler) GetHelp

func (fh *FullHandler) GetHelp() HelpMeta

func (*FullHandler) GetName

func (fh *FullHandler) GetName() string

func (*FullHandler) Run

func (fh *FullHandler) Run(ce *Event)

func (*FullHandler) ShowInHelp added in v0.15.0

func (fh *FullHandler) ShowInHelp(ce *Event) bool

type Handler

type Handler interface {
	MinimalHandler
	GetName() string
}

type HelpMeta

type HelpMeta struct {
	Command     string
	Section     HelpSection
	Description string
	Args        string
}

func (*HelpMeta) String

func (hm *HelpMeta) String() string

type HelpSection

type HelpSection struct {
	Name  string
	Order int
}

type HelpfulHandler

type HelpfulHandler interface {
	Handler
	GetHelp() HelpMeta
	ShowInHelp(*Event) bool
}

type MinimalHandler

type MinimalHandler interface {
	Run(*Event)
}

type MinimalHandlerFunc

type MinimalHandlerFunc func(*Event)

func (MinimalHandlerFunc) Run

func (mhf MinimalHandlerFunc) Run(ce *Event)

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

func NewProcessor

func NewProcessor(bridge *bridge.Bridge) *Processor

NewProcessor creates a Processor

func (*Processor) AddHandler

func (proc *Processor) AddHandler(handler Handler)

func (*Processor) AddHandlers

func (proc *Processor) AddHandlers(handlers ...Handler)

func (*Processor) Handle

func (proc *Processor) Handle(roomID id.RoomID, eventID id.EventID, user bridge.User, message string, replyTo id.EventID)

Handle handles messages to the bridge

Jump to

Keyboard shortcuts

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