Added default route handler for replying to unknown command, closing #22

master
Matthieu Lalonde 5 years ago
parent eae570f3a8
commit 79cf16f660

@ -25,9 +25,30 @@ func (b *Type) loadDiscordHandlers() {
// User commands
b.dg.Router.Route("msg", "Message an AltVR user", b.handleSendMessage)
b.dg.Router.Route("status", "Show the current AltVR user status", b.handleStatusCheck)
b.dg.Router.Default, _ = b.dg.Router.Route("default", "", b.handleDefault)
b.dg.Session.AddHandler(b.handleMessageReplies)
}
/*
** User commands
*/
func (b *Type) handleDefault(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
if !b.checkUserRole(dm.Author.ID, RoleUser) {
b.replyPermissionDenied(ds, dm, ctx)
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("unknown_command", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
}
// XXX Don't allow messaging the bot
func (b *Type) handleSendMessage(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
@ -478,6 +499,7 @@ func (b *Type) handleForceCheck(ds *discordgo.Session, dm *discordgo.Message, ct
b.replyPermissionDenied(ds, dm, ctx)
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
log.Println("Checking for incoming friendship request")
fr, _ := b.avr.FetchPendingFriendshipRequests()
if len(fr) > 0 {
@ -488,6 +510,13 @@ func (b *Type) handleForceCheck(ds *discordgo.Session, dm *discordgo.Message, ct
if len(pm) > 0 {
b.handleNewPendingConversation(pm)
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
}
/*
@ -499,6 +528,7 @@ func (b *Type) handleReload(ds *discordgo.Session, dm *discordgo.Message, ctx *m
b.replyPermissionDenied(ds, dm, ctx)
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
log.Println("Reloading bot data")
b.loadUserFile()
err := b.avr.FetchMyUser()
@ -506,6 +536,13 @@ func (b *Type) handleReload(ds *discordgo.Session, dm *discordgo.Message, ctx *m
log.Printf("Error while reloading own user data: %+v\n", err)
}
b.dg.UpdateAvatar(b.avr.GetAvatarURL())
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
}
/*

@ -4,6 +4,9 @@ import (
"fmt"
"log"
"reflect"
"strings"
"git.lalonde.me/matth/AltVRBot/pkg/utils"
)
type msgMode uint
@ -39,6 +42,7 @@ var (
"all_done": "All done!",
"unauthorized_user": "Sorry, you are not authorized to do this!",
"invalid_command": "Invalid command format!",
"unknown_command": "Uknown command, try `help` to display the available command.",
"unknown_error": "I couldn't not process your request due to an unknown error!",
"auser_unknown_friend": "I don't know about this user, are you sure they are one of my friends and the username is correct?",
"auser_known_user": "I already know about this user!",
@ -58,7 +62,8 @@ var (
"all_done": "Alright alright, stop bugging me already, I got it done for you, you fuck!",
"unauthorized_user": "Fartface, who the fuck do you think you are?!? You're not allowed to do that you lowlife!",
"invalid_command": "You drunk or something?",
"unknown_error": "_BOFH_",
"unknown_command": "I'd do that for you, but I won't because: _BOFH_",
"unknown_error": "An unknown error occured, probably because: _BOFH_",
"auser_unknown_friend": "You dimwit, you should know I don't know who this idiot is. Do I really want them to be my friend? I don't know, but maybe they do!",
"auser_known_user": "Fuckwad, I already know about this asshole!",
"aemoji_unknown_user": "Who the fuck is that? Maybe try to tell me first you airhead!",
@ -77,6 +82,7 @@ var (
"all_done": "I did it for you, sweetie!",
"unauthorized_user": "I wished I could let you do that, but sadly even your good looks aren't enough to allow me!",
"invalid_command": "Love, your beauty is blinding me and I don't understand what you mean!",
"unknown_command": "Sugar plum, I love you, but I don't know what it is you want help with!",
"unknown_error": "We'd all love to see that happen, but the stars weren't aligned today, something unexpected happened",
"auser_unknown_friend": "I've never heard of this hotie before, would you make sure they have befriended me and the username is correct?",
"auser_known_user": "Bae, I already know this person, we were all in that cuddle puddle together the other night!",
@ -115,8 +121,8 @@ func (b *Type) getMessageString(msgID string, params ...interface{}) string {
mode = msgModeNormal
}
if val, ok := msgStrings[mode][msgID]; ok {
if val == "_BOFH_" {
val = getBOFHExcuse()
if strings.Contains(val, "_BOFH_") {
val = strings.ReplaceAll(val, "_BOFH_", utils.GetBOFHExcuse())
}
return fmt.Sprintf(val, p...)
}

Loading…
Cancel
Save