Added flexible msg modes, added per user msg mode, cleanup, added user discord emoji getter

master
Matthieu Lalonde 5 years ago
parent a8e18a193e
commit 0d348df4ef

@ -45,7 +45,15 @@ type User struct {
DiscordName string
DiscordEmoji UserEmoji
Role Roles
isRude bool
MsgMode msgMode
}
// GetDiscordEmoji If it exists, builds a discord emoji for the user
func (u *User) GetDiscordEmoji() string {
if u.DiscordEmoji.ID != "" {
return fmt.Sprintf("<:%s:%s> ", u.DiscordEmoji.Name, u.DiscordEmoji.ID)
}
return ""
}
// Roles determines the bot user roles
@ -74,7 +82,7 @@ type Type struct {
dg *discord.Discord
avr altvr.AltVR
users []User
isRude bool // XXX Trigger automatically on NSFW Channels?
msgMode msgMode
isQuiet bool
frPending []FriendshipRequestPending
convos map[string]string
@ -101,11 +109,25 @@ func (b *Type) setFlags() {
if b.AltVRPassword == "" {
flag.StringVar(&b.AltVRPassword, "p", "", "AltVR Password")
}
flag.BoolVar(&b.isRude, "r", false, "Turn on rude mode")
if !b.isRude {
if value, ok := os.LookupEnv("DG_IS_RUDE"); ok {
b.isRude = (value == "true")
var mode string
flag.StringVar(&mode, "m", "", "Select the reply message mode <"+msgModeNormalString+"|"+msgModeRudeString+"|"+msgModeFlirtyString+">")
if mode == "" {
if value, ok := os.LookupEnv("DG_MSG_MODE"); ok {
mode = value
}
}
switch mode {
case msgModeFlirtyString:
b.msgMode = msgModeFlirty
case msgModeRudeString:
b.msgMode = msgModeRude
case msgModeNormalString:
b.msgMode = msgModeNormal
default:
if mode != "" {
fmt.Printf("Unknown message mode `%s` defaulting to normal\n", mode)
}
b.msgMode = msgModeNormal
}
flag.BoolVar(&b.isQuiet, "q", false, "Turn on quiet mode (don't be verbose on the discord chat)")
flag.Parse()
@ -128,7 +150,7 @@ func (b *Type) Start() {
b.loadDiscordHandlers()
if !b.isQuiet {
s := b.getReplyMessage("online_welcome")
s := b.getMessageString("online_welcome")
if _, err := b.dg.Session.ChannelMessageSend(b.DGcID, s); err != nil {
log.Printf("Error sending welcome message: %+v\n", err)
}
@ -235,7 +257,7 @@ func (b *Type) handleNewFriendshipRequests(fr []altvr.Friendship) {
}
if !found {
u := b.avr.GetFriend(rr.UserID)
s := b.getReplyMessage("new_friendship_requested", u.GetDisplayName())
s := b.getMessageString("new_friendship_requested", u.GetDisplayName())
if msg, err := b.dg.Session.ChannelMessageSend(b.DGcID, s); err == nil {
b.frPending = append(b.frPending, FriendshipRequestPending{
Friendship: rr,

@ -13,172 +13,23 @@ import (
"github.com/bwmarrin/discordgo"
)
var (
commandFormats = map[string]string{
"auser": "<Altspace VR Username> <Discord Mention> [Discord Emoji]",
"aemoji": "<Discord Mention> <Discord Emoji>",
"msg": "<Discord Mention> ...",
"accept": "(As reply) <Discord Mention> [Discord Emoji]",
"deny": "(As reply)",
}
commandReplies = map[string]string{
"online_welcome": "Hello, AltVRBot online and here to serve!",
"all_done": "All done!",
"unauthorized_user": "Sorry, you are not authorized to do this!",
"invalid_command": "Invalid command format!",
"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!",
"aemoji_uknow_user": "I don't know about this user, try to associate it first!",
"msg_unknown_sender": "I don't know you! You must be associated first!",
"msg_unknown_receipient": "I don't know about <@!%s>! They must be associated first!",
"msg_all_done_truncated": "All done, however your message was too long and truncated!",
"new_friendship_requested": "I just heard that %s would like to become friends, should I accept?",
"accept_unknown_reference": "Unknown reference, are you sure you are replying to the right message? Perhaps the request was withdrawn!",
}
commandRepliesRude = map[string]string{
"online_welcome": "Ah fuck, back to work already? Well message me, maybe I'll help you anyway!",
"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_",
"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_uknow_user": "Who the fuck is that? Maybe try to tell me first you airhead!",
"msg_unknown_sender": "Never heard of you chucklefuck! You even registered?",
"msg_unknown_receipient": "I don't know about this chickenfucker named <@!%s>! They must be associated first!",
"msg_all_done_truncated": "Ok ok I did it you shitstick, but you're a verbose fuck so I had to cut your message off a bit!",
"new_friendship_requested": "Have you heard about this dipshit named %s, they think they're cool enough, ha! Should we let that numskull in?",
"accept_unknown_reference": "Numnuts, I don't know what you're talking about! That user might have been too cool for you, or you're just fucking confused!",
}
)
func (b *Type) loadDiscordHandlers() {
// XXX: Status [Discord Mention] reload the online users states and display
// Admin commands
// XXX: Promote
b.dg.Router.Route("reload", "Reload the bot's data and configs", b.handleReload)
// Moderator commands
// XXX: Remove
b.dg.Router.Route("auser", "Associates an AltVR user to a discord user", b.handleAssociateUser)
b.dg.Router.Route("aemoji", "Associates or updates an AltVR user to a discord guild emoji", b.handleAssociateEmoji)
b.dg.Router.Route("accept", "Accept a pending friendship request", b.handleAcceptFriendship)
b.dg.Router.Route("deny", "Deny a pending friendship request", b.handleDenyFriendship)
// XXX: Remove
b.dg.Router.Route("reload", "Reload the bot's data and configs", b.handleReload)
b.dg.Router.Route("check", "Force a recheck of pending friendship requests and messsages", b.handleForceCheck)
// User commands
b.dg.Router.Route("msg", "Message an AltVR user", b.handleSendMessage)
// XXX: Promote
b.dg.Router.Route("status", "Show the current AltVR user status", b.handleStatusCheck)
b.dg.Session.AddHandler(b.handleMessageReplies)
}
func (b *Type) handleAssociateUser(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleModerator) && len(b.users) != 0 {
b.replyPermissionDenied(ds, dm, ctx)
return
}
c := strings.TrimSpace(ctx.Content)
p := strings.Split(c, " ")
if len(p) < 3 || len(p) > 4 {
b.replyInvalidCommandFormat(ds, dm, ctx, "auser")
return
}
// XXX
discordID := strings.Trim(strings.Replace(p[2], "@!", "", -1), "<>")
friend := b.avr.GetFriendByUsername(p[1])
if friend.Username == "" {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("auser_unknown_friend"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
u, _ := b.getUserByDiscordID(discordID)
if u.AltVRUserID != "" {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("auser_known_user"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
e := UserEmoji{}
if len(p) == 4 {
s := strings.Split(strings.Trim(p[3], "<>"), ":")
e.ID = s[2]
e.Name = s[1]
}
role := RoleUser
if len(b.users) == 0 {
role = RoleAdmin
}
b.users = append(b.users, User{
AltVRUserID: friend.UserID,
DiscordID: discordID,
DiscordName: dm.Mentions[len(dm.Mentions)-1].Username,
DiscordEmoji: e,
Role: role,
isRude: false,
})
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("all_done"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
if err := b.saveUserFile(); err != nil {
log.Printf("Error while saving user file: %+v\n", err)
}
}
func (b *Type) handleAssociateEmoji(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleModerator) {
b.replyPermissionDenied(ds, dm, ctx)
return
}
c := strings.TrimSpace(ctx.Content)
p := strings.Split(c, " ")
if len(p) != 3 {
b.replyInvalidCommandFormat(ds, dm, ctx, "aemoji")
return
}
// XXX
discordID := strings.Trim(strings.Replace(p[1], "@!", "", -1), "<>")
u, err := b.getUserByDiscordID(discordID)
if err != nil {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("aemoji_unknown_user"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
e := UserEmoji{}
if len(p) == 4 {
s := strings.Split(strings.Trim(p[2], "<>"), ":")
e.ID = s[2]
e.Name = s[1]
}
u.DiscordEmoji = e
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("all_done"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
if err := b.saveUserFile(); err != nil {
log.Printf("Error while saving user file: %+v\n", err)
}
}
// 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)
@ -188,7 +39,7 @@ func (b *Type) handleSendMessage(ds *discordgo.Session, dm *discordgo.Message, c
u, err := b.getUserByDiscordID(dm.Author.ID)
if err != nil {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("msg_unknown_sender"),
b.getMessageString("msg_unknown_sender"),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -205,7 +56,17 @@ func (b *Type) handleSendMessage(ds *discordgo.Session, dm *discordgo.Message, c
uu, err := b.getUserByDiscordID(discordID)
if err != nil {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("msg_unknown_receipient", discordID),
b.getMessageString("msg_unknown_receipient", u, discordID),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
if discordID == b.dg.User.ID {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("msg_invalid_receipient", u, discordID),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -225,7 +86,7 @@ func (b *Type) handleSendMessage(ds *discordgo.Session, dm *discordgo.Message, c
if err := b.avr.PostNewConversation(uu.AltVRUserID, c); err != nil {
log.Printf("Error while sending message: %+v\n", err)
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("unknown_error"),
b.getMessageString("unknown_error", u),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -237,7 +98,7 @@ func (b *Type) handleSendMessage(ds *discordgo.Session, dm *discordgo.Message, c
rm = "msg_all_done_truncated"
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage(rm),
b.getMessageString(rm, u),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -260,7 +121,7 @@ func (b *Type) handleMessageReplies(ds *discordgo.Session, mc *discordgo.Message
u, err := b.getUserByDiscordID(mc.Author.ID)
if err != nil {
b.dg.Session.ChannelMessageSendReply(mc.ChannelID,
b.getReplyMessage("msg_unknown_sender"),
b.getMessageString("msg_unknown_sender"),
&discordgo.MessageReference{
MessageID: mc.ID,
ChannelID: mc.ChannelID,
@ -276,7 +137,7 @@ func (b *Type) handleMessageReplies(ds *discordgo.Session, mc *discordgo.Message
if err := b.avr.PostNewConversation(b.convos[mc.MessageReference.MessageID], msg); err != nil {
log.Printf("Error while replying to message: %+v\n", err)
b.dg.Session.ChannelMessageSendReply(mc.ChannelID,
b.getReplyMessage("unknown_error"),
b.getMessageString("unknown_error", u),
&discordgo.MessageReference{
MessageID: mc.ID,
ChannelID: mc.ChannelID,
@ -288,7 +149,7 @@ func (b *Type) handleMessageReplies(ds *discordgo.Session, mc *discordgo.Message
rm = "msg_all_done_truncated"
}
b.dg.Session.ChannelMessageSendReply(mc.ChannelID,
b.getReplyMessage(rm),
b.getMessageString(rm, u),
&discordgo.MessageReference{
MessageID: mc.ID,
ChannelID: mc.ChannelID,
@ -297,6 +158,196 @@ func (b *Type) handleMessageReplies(ds *discordgo.Session, mc *discordgo.Message
}
}
func (b *Type) handleStatusCheck(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
if !b.checkUserRole(dm.Author.ID, RoleUser) {
b.replyPermissionDenied(ds, dm, ctx)
return
}
u, _ := b.getUserByDiscordID(dm.Author.ID)
um := b.getMentions(dm.Mentions)
c := strings.TrimSpace(ctx.Content)
if len(um) > 0 {
reg := regexp.MustCompile(fmt.Sprintf(" <@!?(%s)>", um[0].ID))
c = reg.ReplaceAllString(c, "")
}
var fids []string
if len(um) == 0 {
for _, f := range b.avr.GetFriendships() {
fids = append(fids, f.FriendID)
}
} else {
for _, du := range um {
bu, err := b.getUserByDiscordID((du.ID))
if err != nil {
log.Printf("Error while discord user data: %+v\n", err)
} else {
fids = append(fids, bu.AltVRUserID)
}
}
}
if err := b.avr.FetchFriends(fids...); err != nil {
log.Printf("Error while fetching friends data: %+v\n", err)
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("unknown_error", u),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
} else {
var msg string
for i, uid := range fids {
au := b.avr.GetFriend(uid)
if au.OnlineStatus == "Online" || au.OnlineStatus == "Available" {
du, err := b.getUserByAltVRUserID((au.UserID))
if err != nil {
continue
}
e := du.GetDiscordEmoji()
if e != "" {
msg += e + " "
}
msg += au.GetDisplayName() + "is current online"
if au.CurrentSpace.Name != "" {
msg += " in " + au.CurrentSpace.Name
}
msg += "."
if i < len(fids)-1 {
msg += "\n"
}
}
}
if msg == "" {
if len(um) == 0 {
msg = b.getMessageString("no_online_users", u)
} else {
msg = b.getMessageString("no_online_requested_users", u)
}
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID, msg,
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
}
}
/*
** Moderator commands
*/
func (b *Type) handleAssociateUser(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleModerator) && len(b.users) != 0 {
b.replyPermissionDenied(ds, dm, ctx)
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
c := strings.TrimSpace(ctx.Content)
p := strings.Split(c, " ")
if len(p) < 3 || len(p) > 4 {
b.replyInvalidCommandFormat(ds, dm, ctx, "auser")
return
}
// XXX
discordID := strings.Trim(strings.Replace(p[2], "@!", "", -1), "<>")
friend := b.avr.GetFriendByUsername(p[1])
if friend.Username == "" {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("auser_unknown_friend", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
u, _ := b.getUserByDiscordID(discordID)
if u.AltVRUserID != "" {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("auser_known_user", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
e := UserEmoji{}
if len(p) == 4 {
s := strings.Split(strings.Trim(p[3], "<>"), ":")
e.ID = s[2]
e.Name = s[1]
}
role := RoleUser
if len(b.users) == 0 {
role = RoleAdmin
}
b.users = append(b.users, User{
AltVRUserID: friend.UserID,
DiscordID: discordID,
DiscordName: dm.Mentions[len(dm.Mentions)-1].Username,
DiscordEmoji: e,
Role: role,
MsgMode: b.msgMode,
})
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
if err := b.saveUserFile(); err != nil {
log.Printf("Error while saving user file: %+v\n", err)
}
}
func (b *Type) handleAssociateEmoji(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleModerator) {
b.replyPermissionDenied(ds, dm, ctx)
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
c := strings.TrimSpace(ctx.Content)
p := strings.Split(c, " ")
if len(p) != 3 {
b.replyInvalidCommandFormat(ds, dm, ctx, "aemoji")
return
}
// XXX
discordID := strings.Trim(strings.Replace(p[1], "@!", "", -1), "<>")
u, err := b.getUserByDiscordID(discordID)
if err != nil {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("aemoji_unknown_user", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
return
}
e := UserEmoji{}
if len(p) == 4 {
s := strings.Split(strings.Trim(p[2], "<>"), ":")
e.ID = s[2]
e.Name = s[1]
}
u.DiscordEmoji = e
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
})
if err := b.saveUserFile(); err != nil {
log.Printf("Error while saving user file: %+v\n", err)
}
}
func (b *Type) handleAcceptFriendship(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleModerator) && len(b.users) != 0 {
@ -307,6 +358,7 @@ func (b *Type) handleAcceptFriendship(ds *discordgo.Session, dm *discordgo.Messa
b.replyInvalidCommandFormat(ds, dm, ctx, "accept")
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
var req FriendshipRequestPending
found := false
for _, fr := range b.frPending {
@ -318,7 +370,7 @@ func (b *Type) handleAcceptFriendship(ds *discordgo.Session, dm *discordgo.Messa
}
if !found {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("accept_unknown_reference"),
b.getMessageString("accept_unknown_reference", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -355,7 +407,7 @@ func (b *Type) handleAcceptFriendship(ds *discordgo.Session, dm *discordgo.Messa
DiscordName: dm.Mentions[len(dm.Mentions)-1].Username,
DiscordEmoji: e,
Role: role,
isRude: false,
MsgMode: b.msgMode,
})
b.avr.AcceptFriendshipRequest(req.Friendship.FriendshipID)
for k, fr := range b.frPending {
@ -365,7 +417,7 @@ func (b *Type) handleAcceptFriendship(ds *discordgo.Session, dm *discordgo.Messa
}
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("all_done"),
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -387,6 +439,7 @@ func (b *Type) handleDenyFriendship(ds *discordgo.Session, dm *discordgo.Message
b.replyInvalidCommandFormat(ds, dm, ctx, "deny")
return
}
uu, _ := b.getUserByDiscordID(dm.Author.ID)
var req FriendshipRequestPending
found := false
for _, fr := range b.frPending {
@ -397,7 +450,7 @@ func (b *Type) handleDenyFriendship(ds *discordgo.Session, dm *discordgo.Message
}
if !found {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("accept_unknown_reference"),
b.getMessageString("accept_unknown_reference", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -413,7 +466,7 @@ func (b *Type) handleDenyFriendship(ds *discordgo.Session, dm *discordgo.Message
}
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID,
b.getReplyMessage("all_done"),
b.getMessageString("all_done", uu),
&discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
@ -439,6 +492,9 @@ func (b *Type) handleForceCheck(ds *discordgo.Session, dm *discordgo.Message, ct
}
}
/*
** Admin commands
*/
func (b *Type) handleReload(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
//fmt.Printf("dm:\t%+v\nctv:\t%+v\n", dm, ctx)
if !b.checkUserRole(dm.Author.ID, RoleAdmin) {
@ -454,6 +510,9 @@ func (b *Type) handleReload(ds *discordgo.Session, dm *discordgo.Message, ctx *m
b.dg.UpdateAvatar(b.avr.GetAvatarURL())
}
/*
** Utilities
*/
func (b *Type) checkUserRole(discordID string, role Roles) bool {
u, err := b.getUserByDiscordID(discordID)
if err != nil {
@ -464,7 +523,8 @@ func (b *Type) checkUserRole(discordID string, role Roles) bool {
}
func (b *Type) replyPermissionDenied(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context) {
b.dg.Session.ChannelMessageSendReply(dm.ChannelID, b.getReplyMessage("unauthorized_user"), &discordgo.MessageReference{
uu, _ := b.getUserByDiscordID(dm.Author.ID)
b.dg.Session.ChannelMessageSendReply(dm.ChannelID, b.getMessageString("unauthorized_user", uu), &discordgo.MessageReference{
MessageID: dm.ID,
ChannelID: dm.ChannelID,
GuildID: dm.GuildID,
@ -472,9 +532,10 @@ func (b *Type) replyPermissionDenied(ds *discordgo.Session, dm *discordgo.Messag
}
func (b *Type) replyInvalidCommandFormat(ds *discordgo.Session, dm *discordgo.Message, ctx *mux.Context, cmd string) {
msg := b.getReplyMessage("invalid_command")
uu, _ := b.getUserByDiscordID(dm.Author.ID)
msg := b.getMessageString("invalid_command", uu)
if usage, ok := commandFormats[cmd]; ok {
msg = msg + " " + usage
msg = msg + " Usage: " + cmd + " " + usage
}
b.dg.Session.ChannelMessageSendReply(dm.ChannelID, msg, &discordgo.MessageReference{
MessageID: dm.ID,
@ -483,22 +544,6 @@ func (b *Type) replyInvalidCommandFormat(ds *discordgo.Session, dm *discordgo.Me
})
}
func (b *Type) getReplyMessage(msgID string, params ...interface{}) string {
if b.isRude {
if val, ok := commandRepliesRude[msgID]; ok {
if val == "_BOFH_" {
val = getBOFHExcuse()
}
return fmt.Sprintf(val, params...)
}
}
if val, ok := commandReplies[msgID]; ok {
return fmt.Sprintf(val, params...)
}
return "Unknown message???"
}
func (b *Type) getMentions(ms []*discordgo.User) []*discordgo.User {
var um []*discordgo.User
for _, u := range ms {
@ -508,11 +553,3 @@ func (b *Type) getMentions(ms []*discordgo.User) []*discordgo.User {
}
return um
}
func truncateString(s string, i int) string {
runes := []rune(s)
if len(runes) > i {
return string(runes[:i])
}
return s
}

@ -0,0 +1,125 @@
package bot
import (
"fmt"
"log"
"reflect"
)
type msgMode uint
const (
msgModeNone = iota
msgModeNormal
msgModeRude
msgModeFlirty
)
const (
msgModeNormalString = "normal"
msgModeRudeString = "rude"
msgModeFlirtyString = "flirty"
)
type msgMap map[string]string
var (
commandFormats = map[string]string{
"auser": "<Altspace VR Username> <Discord Mention> [Discord Emoji]",
"aemoji": "<Discord Mention> <Discord Emoji>",
"msg": "<Discord Mention> ...",
"accept": "(As reply) <Discord Mention> [Discord Emoji]",
"deny": "(As reply)",
"status": "[Discord Mention...]",
}
msgStrings = map[msgMode]msgMap{
msgModeNormal: {
"online_welcome": "Hello, AltVRBot online and here to serve!",
"all_done": "All done!",
"unauthorized_user": "Sorry, you are not authorized to do this!",
"invalid_command": "Invalid command format!",
"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!",
"aemoji_unknown_user": "I don't know about this user, try to associate it first!",
"msg_unknown_sender": "I don't know you! You must be associated first!",
"msg_unknown_receipient": "I don't know about <@!%s>! They must be associated first!",
"msg_invalid_receipient": "I can't message this user because it probably is myself!",
"msg_all_done_truncated": "All done, however your message was too long and truncated!",
"new_friendship_requested": "I just heard that %s would like to become friends, should I accept?",
"accept_unknown_reference": "Unknown reference, are you sure you are replying to the right message? Perhaps the request was withdrawn!",
"no_online_users": "Seems like no one is online, how lonely!",
"no_online_requested_users": "These people aren't online right now, sorry!",
},
msgModeRude: {
"online_welcome": "Ah fuck, back to work already? Well message me, maybe I'll help you anyway!",
"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_",
"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!",
"msg_unknown_sender": "Never heard of you chucklefuck! You even registered?",
"msg_unknown_receipient": "I don't know about this chickenfucker named <@!%s>! They must be associated first!",
"msg_invalid_receipient": "Seems obvious, but I'm gonna explain it for you half brained: I can't message myself!",
"msg_all_done_truncated": "Ok ok I did it you shitstick, but you're a verbose fuck so I had to cut your message off a bit!",
"new_friendship_requested": "Have you heard about this dipshit named %s, they think they're cool enough, ha! Should we let that numskull in?",
"accept_unknown_reference": "Numnuts, I don't know what you're talking about! That user might have been too cool for you, or you're just fucking confused!",
"no_online_users": "Everyone else has better things to do than talk you, loser!",
"no_online_requested_users": "Looks like these fucks have better things to do than talk to you, loser!",
},
msgModeFlirty: {
"online_welcome": "Hi there beautiful people, it'll be my delight to serve you!",
"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_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!",
"aemoji_unknown_user": "Sweetiepie, I don't know them, maybe you could introduce us over a glass of wine and some candles?",
"msg_unknown_sender": "Honey, I've never met you before, invite me on a date before we get cozy!",
"msg_unknown_receipient": "I've never heard of <@!%s>, but they sure do sound sexy! Maybe you could tell me more about them?",
"msg_invalid_receipient": "I'd love to write to this lovely person, but they aren't in my rolodex yet!",
"msg_all_done_truncated": "I did it for you sweetie, however your passion was too great and I had to truncate your message!",
"new_friendship_requested": "Looks like %s would like to get cozy, should we let them in the hot tub?",
"accept_unknown_reference": "As sexy as you are, I still can't find a reference to this request. Perhaps it was withdrawn!",
"no_online_users": "I'm sory sweetheart, no one's online, but I'll always be there for you!",
"no_online_requested_users": "I'm sory sweetheart, these beautiful people arent online, but I'll always be there for you!",
},
}
)
func (b *Type) getMessageString(msgID string, params ...interface{}) string {
mode := b.msgMode
p := params
if len(p) >= 1 {
if reflect.TypeOf(p[0]) == reflect.TypeOf(User{}) {
u := p[0].(User)
if u.MsgMode != msgModeNone {
mode = u.MsgMode
}
p = p[1:]
}
}
if mode == msgModeNone {
mode = msgModeNormal
}
if _, ok := msgStrings[mode][msgID]; !ok {
mode = msgModeNormal
}
if mode != msgModeNormal && msgStrings[mode][msgID] == "" {
mode = msgModeNormal
}
if val, ok := msgStrings[mode][msgID]; ok {
if val == "_BOFH_" {
val = getBOFHExcuse()
}
return fmt.Sprintf(val, p...)
}
log.Printf("Trying to fetch unknown message with key: %s\n", msgID)
return "Unknown message???"
}

@ -0,0 +1,9 @@
package bot
func truncateString(s string, i int) string {
runes := []rune(s)
if len(runes) > i {
return string(runes[:i])
}
return s
}
Loading…
Cancel
Save