automod

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2018 License: MIT Imports: 29 Imported by: 0

README

Automod

Automod provides some auto moderation features.

Features:

  • Ban websites
  • Ban words
  • Spam detection
  • Ban invite links
  • Mention spam detection

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinSwearWords = map[string]bool{
	"anal":        true,
	"anus":        true,
	"arse":        true,
	"ass":         true,
	"ballsack":    true,
	"bastard":     true,
	"bitch":       true,
	"biatch":      true,
	"blowjob":     true,
	"bollock":     true,
	"bollok":      true,
	"boner":       true,
	"boob":        true,
	"buttplug":    true,
	"clitoris":    true,
	"cock":        true,
	"crap":        true,
	"cunt":        true,
	"dick":        true,
	"dildo":       true,
	"dyke":        true,
	"fag":         true,
	"feck":        true,
	"fellate":     true,
	"fellatio":    true,
	"felching":    true,
	"fuck":        true,
	"fudgepacker": true,
	"hell":        true,
	"jerk":        true,
	"jizz":        true,
	"knobend":     true,
	"labia":       true,
	"muff":        true,
	"nigger":      true,
	"nigga":       true,
	"penis":       true,
	"piss":        true,
	"poop":        true,
	"pube":        true,
	"pussy":       true,
	"queer":       true,
	"scrotum":     true,
	"sex":         true,
	"shit":        true,
	"sh1t":        true,
	"slut":        true,
	"smegma":      true,
	"spunk":       true,
	"tit":         true,
	"tosser":      true,
	"turd":        true,
	"twat":        true,
	"vagina":      true,
	"wank":        true,
	"whore":       true,
	"tits":        true,
	"titty":       true,
	"asshole":     true,
	"fvck":        true,
	"asshat":      true,
	"pu55y":       true,
	"pen1s":       true,
}

This list is in alphabethical order Open a pr or bug me on discord if you want a word added

Functions

func CheckMessage

func CheckMessage(m *discordgo.Message, client *redis.Client)

func Dir

func Dir(useLocal bool, name string) http.FileSystem

Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.

func ExtraPostMW

func ExtraPostMW(inner http.Handler) http.Handler

Invalidates the cache

func FS

func FS(useLocal bool) http.FileSystem

FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSByte

func FSByte(useLocal bool, name string) ([]byte, error)

FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.

func FSMustByte

func FSMustByte(useLocal bool, name string) []byte

FSMustByte is the same as FSByte, but panics if name is not present.

func FSMustString

func FSMustString(useLocal bool, name string) string

FSMustString is the string version of FSMustByte.

func FSString

func FSString(useLocal bool, name string) (string, error)

FSString is the string version of FSByte.

func HandleAutomod

func HandleAutomod(w http.ResponseWriter, r *http.Request) interface{}

func HandleMessageCreate

func HandleMessageCreate(evt *eventsystem.EventData)

func HandleMessageUpdate

func HandleMessageUpdate(evt *eventsystem.EventData)

func HandleUpdateAutomodRules

func HandleUpdateAutomodRules(event *pubsub.Event)

Invalidate the cache when the rules have changed

func KeyConfig

func KeyConfig(gID int64) string

func KeyEnabled

func KeyEnabled(gID int64) string

Redis keys

func KeyViolations

func KeyViolations(gID, uID int64, violation string) string

func RegisterPlugin

func RegisterPlugin()

Types

type BaseRule

type BaseRule struct {
	Enabled bool

	ViolationsExpire int `valid:"0,44640"`

	// Execute these punishments after certain number of repeated violaions
	MuteAfter    int `valid:"0,1000"`
	MuteDuration int `valid:"0,44640"`
	KickAfter    int `valid:"0,1000"`
	BanAfter     int `valid:"0,1000"`

	IgnoreRole     string   `valid:"role,true"`
	IgnoreChannels []string `valid:"channel,false"`
}

func (BaseRule) GetMuteDuration

func (r BaseRule) GetMuteDuration() int

func (BaseRule) IgnoreRoleInt

func (r BaseRule) IgnoreRoleInt() int64

func (BaseRule) PushViolation

func (r BaseRule) PushViolation(client *redis.Client, key string) (p Punishment, err error)

func (BaseRule) ShouldIgnore

func (r BaseRule) ShouldIgnore(evt *discordgo.Message, m *discordgo.Member) bool

Returns true if this rule should be ignored

type Condition

type Condition string

type Config

type Config struct {
	Enabled bool
	Spam    *SpamRule    `valid:"traverse"`
	Mention *MentionRule `valid:"traverse"`
	Invite  *InviteRule  `valid:"traverse"`
	Links   *LinksRule   `valid:"traverse"`
	Sites   *SitesRule   `valid:"traverse"`
	Words   *WordsRule   `valid:"traverse"`
}

func CachedGetConfig

func CachedGetConfig(client *redis.Client, gID int64) (*Config, error)

CachedGetConfig either retrieves from local application cache or redis

func GetConfig

func GetConfig(client *redis.Client, guildID int64) (config *Config, err error)

Behold the almighty number of return values on this one!

func NewConfig

func NewConfig() *Config

func (Config) Name

func (c Config) Name() string

func (Config) Save

func (c Config) Save(client *redis.Client, guildID int64) error

type CtxKey

type CtxKey int
const (
	CurrentConfig CtxKey = iota
)

type GeneralForm

type GeneralForm struct {
	Enabled bool
}

type InviteRule

type InviteRule struct {
	BaseRule `valid:"traverse"`
}

func (*InviteRule) Check

func (i *InviteRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

type LinksRule

type LinksRule struct {
	BaseRule `valid:"traverse"`
}

func (*LinksRule) Check

func (l *LinksRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

type MentionRule

type MentionRule struct {
	BaseRule `valid:"traverse"`

	Treshold int `valid:"0,500"`
}

func (*MentionRule) Check

func (m *MentionRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

type Plugin

type Plugin struct{}

func (*Plugin) InitBot

func (p *Plugin) InitBot()

func (*Plugin) InitWeb

func (p *Plugin) InitWeb()

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) StartBot

func (p *Plugin) StartBot()

type Punishment

type Punishment int
const (
	PunishNone Punishment = iota
	PunishMute
	PunishKick
	PunishBan
)

type Rule

type Rule interface {
	Check(m *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)
	ShouldIgnore(msg *discordgo.Message, m *discordgo.Member) bool
	GetMuteDuration() int
}

type SitesRule

type SitesRule struct {
	BaseRule `valid:"traverse"`

	BuiltinBadSites  bool
	BuiltinPornSites bool

	BannedWebsites string `valid:",10000"`
	// contains filtered or unexported fields
}

func (*SitesRule) Check

func (s *SitesRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

func (*SitesRule) GetCompiled

func (w *SitesRule) GetCompiled() []string

type SpamRule

type SpamRule struct {
	BaseRule `valid:"traverse"`

	NumMessages int `valid:"0,1000"`
	Within      int `valid:"0,100"`
}

func (*SpamRule) Check

func (s *SpamRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

Triggers when a certain number of messages is found by the same author within a timeframe

type WordsRule

type WordsRule struct {
	BaseRule          `valid:"traverse"`
	BuiltinSwearWords bool
	BannedWords       string `valid:",10000"`
	// contains filtered or unexported fields
}

func (*WordsRule) Check

func (w *WordsRule) Check(evt *discordgo.Message, cs *dstate.ChannelState, client *redis.Client) (del bool, punishment Punishment, msg string, err error)

func (*WordsRule) CheckMessage

func (w *WordsRule) CheckMessage(content string) (word string)

func (*WordsRule) GetCompiled

func (w *WordsRule) GetCompiled() map[string]bool

Jump to

Keyboard shortcuts

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