started the facelift of the repo, adding in bans and timeouts. That comes with some restructure. Also implementing a goroutine limit for command handlers and options around that, as well as moving the intents to options to allow stronger restrictions
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package bolt
|
|
|
|
import (
|
|
dg "github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
type Option func(b *bolt)
|
|
|
|
type LogLevel int
|
|
|
|
type Permission dg.Intent
|
|
|
|
type HandlerLevel int
|
|
|
|
const (
|
|
LogLevelAll LogLevel = iota //log all messages, and errors
|
|
LogLevelCmd LogLevel = iota //log only commands and responses, and errors
|
|
LogLevelErr LogLevel = iota //log only errors
|
|
LogLevelNone LogLevel = iota //log nothing, let the handlers sort it out
|
|
|
|
msgPerms dg.Intent = dg.IntentGuilds |
|
|
dg.IntentGuildMembers |
|
|
dg.IntentGuildPresences |
|
|
dg.IntentMessageContent |
|
|
dg.IntentsGuildMessages
|
|
|
|
MessagePermissions Permission = Permission(msgPerms)
|
|
ReactionPermissions Permission = Permission(dg.IntentGuildMessageReactions)
|
|
//we also need a ModeratorPermissions for banning, kicking, etc.
|
|
)
|
|
|
|
func WithPermissions(perms ...Permission) Option {
|
|
return func(b *bolt) {
|
|
var fullPerms dg.Intent
|
|
for _, p := range perms {
|
|
fullPerms |= dg.Intent(p)
|
|
}
|
|
|
|
//set intents
|
|
b.Identify.Intents = fullPerms
|
|
}
|
|
}
|
|
|
|
func WithMaxGoroutines(max int) Option {
|
|
return func(b *bolt) {
|
|
b.maxRoutines = max
|
|
}
|
|
}
|
|
|
|
// sets the substring that must be present at the beginning of the message to indicate a command
|
|
func WithIndicator(i string) Option {
|
|
return func(b *bolt) {
|
|
b.indicator = i
|
|
}
|
|
}
|
|
|
|
// sets the log level to determine how much bolt logs
|
|
func WithLogLevel(lvl LogLevel) Option {
|
|
return func(b *bolt) {
|
|
b.logLvl = lvl
|
|
}
|
|
}
|