fallacy

package module
v0.0.0-...-b4e4385 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 15 Imported by: 0

README

fallacy

GoDoc

"fallacy bot good" – a logician

About

Fallacy is a custom high performance Matrix moderation bot written for Spite. Born out of the deficiencies of similar moderation bots, it aims to be simple, fast, and efficient.

Much of the design was inspired by @rSophieBot.

Features

  • Written in Go, making use of the language's native concurrency primitives
  • Intuitive message purging support by replying to the oldest message to purge
  • Kicking/banning users via glob, as well as preemptive bans for valid MXID literals
  • Pinning messages via reply
  • Prejudiced against Firefox users
  • Automatic joining of upgraded rooms
  • Puppeting via the bot to say messages

In-progress

  • Muting users via power levels
    • There are serious problems with the current implementation due to a lack of a hash map storing the previous power level; this will be rectified soon.
  • Proper room-specific settings
  • Extensive ban-list support including an exception list for handling of admin actions
    • Glob-matching for both disallowed display names and MXIDs including differing actions to take for both

Future

  • Spam/flooding detection
  • Features relying on time
    • Banning all new users from a specific homeserver for a specified length of time
    • Automatically unmuting users after a specified period of time including preventing admins from using it on each other
  • Granular purging support as well as other features only made possible by tracking the previous message
  • Promoting and demoting users
  • "Slow mode" or shadowbanning via silently redacting a user's messages if the last one was sent within a time window

Building

Download the Go toolchain from go.dev and build.

go install github.com/qua3k/fallacy/fallacy@latest

Documentation

Overview

Package fallacy implements the fallacy bot library.

Index

Constants

This section is empty.

Variables

View Source
var (

	// Client is the currently connected Client
	Client *mautrix.Client
)

Functions

func BanServer

func BanServer(roomID id.RoomID, homeserver string) (err error)

BanServer bans a server by adding it to the room ACL.

func BanUser

func BanUser(body []string, ev event.Event)

func CommandPurge

func CommandPurge(body []string, ev event.Event)

CommandPurge is a simple function to be invoked by the purge keyword.

func HandleMember

func HandleMember(s mautrix.EventSource, ev *event.Event)

HandleMember handles `m.room.member` events.

func HandleMessage

func HandleMessage(s mautrix.EventSource, ev *event.Event)

HandleMessage handles m.room.message events.

func HandleServerPolicy

func HandleServerPolicy(s mautrix.EventSource, ev *event.Event)

HandleServerPolicy handles m.policy.rule.server events. Initially limited to room admins but could possibly be extended to members of specific rooms.

func HandleTombstone

func HandleTombstone(_ mautrix.EventSource, ev *event.Event)

HandleTombStone handles m.room.tombstone events, automatically joining the new room.

func HandleUserPolicy

func HandleUserPolicy(s mautrix.EventSource, ev *event.Event)

HandleUserPolicy handles m.policy.rule.user events by banning literals and glob banning globs.

func ImportList

func ImportList(body []string, ev event.Event)

ImportList imports a banlist from another room.

func KickUser

func KickUser(body []string, ev event.Event)

func MuteUser

func MuteUser(body []string, ev event.Event)

MuteUser mutes a target user in a specified room by utilizing power levels.

func PinMessage

func PinMessage(body []string, ev event.Event)

PinMessage pins the replied-to event.

func PurgeMessages

func PurgeMessages(body []string, ev event.Event)

PurgeMessages redacts all message events newer than the specified event ID. It's loosely inspired by Telegram's SophieBot mechanics.

func PurgeUser

func PurgeUser(body []string, ev event.Event)

PurgeUser redacts optionally a limit or all messages sent by a specified user. This is implemented efficiently using a filter to only obtain the events sent by the user.

func RedactMessage

func RedactMessage(ev event.Event) (err error)

RedactMessage only redacts message events, skipping redaction events, already redacted events, and state events.

func Register

func Register(keyword string, callback Callback)

Register registers a command with a keyword.

func SayMessage

func SayMessage(body []string, ev event.Event)

SayMessage sends a message into the chat.

func UnmuteUser

func UnmuteUser(body []string, ev event.Event)

UnmuteUser unmutes a target user in a specified room by utilizing power levels.

func WelcomeMember

func WelcomeMember(display string, sender id.UserID, roomID id.RoomID) (err error)

WelcomeMember welcomes a member via their display name. The display name is calculated as per https://spec.matrix.org/v1.1/Client-server-api/#calculating-the-display-name-for-a-user.

Types

type Callback

type Callback struct {
	Function func(command []string, event event.Event)
	Min      int
}

type Config

type Config struct {
	// the name of the bot
	Name string
	// Device ID, use for avoiding flooding sessions with device IDs.
	DeviceID id.DeviceID `toml:"device_id"`

	// the homeserver to connect to, e.g., https://matrix-client.matrix.org
	Homeserver string
	// the username (mxid) to connect with, e.g., @fallacy:matrix.org
	Username id.UserID
	// the password to the account
	Password string

	// the rooms the bot responds in, omit to allow all rooms
	PermittedRooms []id.RoomID `toml:"permitted_rooms"`
}

func (Config) Login

func (c Config) Login() error

func (Config) New

func (c Config) New() error

New initializes the library and should be called before any other functions. It is safe to call more than once, as it is only initialized once.

type Syncer

type Syncer struct {

	// ParseEventContent determines whether or not event content should be parsed before passing to handlers.
	ParseEventContent bool
	// ParseErrorHandler is called when event.Content.ParseRaw returns an error.
	// If it returns false, the event will not be forwarded to listeners.
	ParseErrorHandler func(ev *event.Event, err error) bool
	// contains filtered or unexported fields
}

func NewSyncer

func NewSyncer() *Syncer

func (*Syncer) GetFilterJSON

func (s *Syncer) GetFilterJSON(id.UserID) *mautrix.Filter

func (*Syncer) OnEvent

func (s *Syncer) OnEvent(callback mautrix.EventHandler)

func (*Syncer) OnEventType

func (s *Syncer) OnEventType(eventType event.Type, callback mautrix.EventHandler)

OnEventType allows callers to be notified when there are new events for the given event type. There are no duplicate checks.

func (*Syncer) OnFailedSync

func (s *Syncer) OnFailedSync(res *mautrix.RespSync, err error) (time.Duration, error)

OnFailedSync always returns a 10 second wait period between failed /syncs, never a fatal error.

func (*Syncer) OnSync

func (s *Syncer) OnSync(callback mautrix.SyncHandler)

func (*Syncer) ProcessResponse

func (s *Syncer) ProcessResponse(res *mautrix.RespSync, since string) (err error)

ProcessResponse processes the /sync response in a way suitable for bots. "Suitable for bots" means a stream of unrepeating events. Returns a fatal error if a listener panics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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