package modules import ( "github.com/bwmarrin/discordgo" "TerraOceanBot/db" "TerraOceanBot/discord/backend" "TerraOceanBot/discord/config" "TerraOceanBot/discord/message" ) var changeTrust = enforceDM(memberFilter(true, enforceArgumentCount( config.ChangeTrustUsage, 2, func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { member, err := backend.GetMemberFromUserFriendlyName(s, command[1]) if err == backend.ErrMemberNotFound { message.InitNewEmbed( config.ErrorChangeTrustTitle, config.ErrorChangeTrustTargetNotFound, config.ErrorColour, ).Send(s, m.ChannelID) return } if err != nil { message.AuditError(s, m.ChannelID, err) return } embed := message.NewEmbed(). SetTitle(config.ChangeTrustPromptTitle). SetColour(config.ChangeTrustPromptColour). AddField(config.ChangeTrustPromptID, member.User.Username+"#"+member.User.Discriminator) if member.Nick != "" { embed.AddField(config.ChangeTrustPromptNick, member.Nick) } embed.AddField(config.ChangeTrustPromptReminderTitle, config.ChangeTrustPromptReminderDescription) msg, err := embed.Send(s, m.ChannelID) if err != nil { message.AuditError(s, m.ChannelID, err) return } queueForReact( msg.ID, []string{emojiOne, emojiTwo, emojiThree, emojiFour, emojiFive, emojiCheck}, member.User.ID, trustCallback, ) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiOne) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiTwo) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiThree) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiFour) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiFive) s.MessageReactionAdd(m.ChannelID, msg.ID, emojiCheck) }, ))) func trustCallback(s *discordgo.Session, r *discordgo.MessageReactionAdd, info interface{}) { target := info.(string) var value int switch r.Emoji.Name { case emojiOne: value = 1 case emojiTwo: value = 2 case emojiThree: value = 3 case emojiFour: value = 4 case emojiFive: value = 5 case emojiCheck: value = db.NuclearOptionVote default: message.AuditInfo(s, "Reaction "+r.Emoji.Name+" was added to trust message ID "+r.MessageID) return } err := backend.UpdateTrust(r.UserID, target, value) if err == db.ErrRecentlyChanged { message.InitNewEmbed( config.ErrorChangeTrustTitle, config.ErrorChangeTrustRecentlyChanged, config.ErrorColour, ).Send(s, r.ChannelID) return } if err != nil { message.AuditError(s, r.ChannelID, err) return } message.InitNewEmbed( config.ChangeTrustSuccessTitle, config.ChangeTrustSuccessDescription, config.SuccessColour, ).Send(s, r.ChannelID) }