mirror of
https://github.com/Fluffy-Bean/Lynxie.git
synced 2025-05-28 22:33:14 +00:00
Add command aliases, cleanup types and order
This commit is contained in:
parent
a70ca23e41
commit
10acb07216
4 changed files with 58 additions and 83 deletions
19
app/app.go
19
app/app.go
|
@ -21,14 +21,16 @@ type Config struct {
|
|||
}
|
||||
|
||||
type App struct {
|
||||
Config Config
|
||||
Commands map[string]Callback
|
||||
Config Config
|
||||
Commands map[string]Callback
|
||||
CommandAliases map[string]string
|
||||
}
|
||||
|
||||
func NewApp(config Config) *App {
|
||||
return &App{
|
||||
Config: config,
|
||||
Commands: make(map[string]Callback),
|
||||
Config: config,
|
||||
Commands: make(map[string]Callback),
|
||||
CommandAliases: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +38,10 @@ func (a *App) RegisterCommand(cmd string, f Callback) {
|
|||
a.Commands[cmd] = f
|
||||
}
|
||||
|
||||
func (a *App) RegisterCommandAlias(alias, cmd string) {
|
||||
a.CommandAliases[alias] = cmd
|
||||
}
|
||||
|
||||
func (a *App) Run() {
|
||||
dg, err := discordgo.New("Bot " + a.Config.Token)
|
||||
if err != nil {
|
||||
|
@ -92,6 +98,11 @@ func (a *App) handler(session *discordgo.Session, message *discordgo.MessageCrea
|
|||
cmd = strings.TrimPrefix(cmd, a.Config.Prefix)
|
||||
cmd, args, _ = strings.Cut(cmd, " ")
|
||||
|
||||
alias, ok := a.CommandAliases[cmd]
|
||||
if ok {
|
||||
cmd = alias
|
||||
}
|
||||
|
||||
callback, ok := a.Commands[cmd]
|
||||
if !ok {
|
||||
// Falling back to default help command
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue