package modules import ( "fmt" "github.com/bwmarrin/discordgo" "TerraOceanBot/discord/backend" "TerraOceanBot/discord/config" ) //adminID is my Discord user ID (chanbakjsd#7968). const adminID = "218983355746746369" func adminOnly(passOn CommandHandler) CommandHandler { return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { if m.Author.ID != adminID { return } passOn(s, m, command) } } var sendAs = adminOnly(enforceArgumentCount(config.SendAsUsage, 3, //!sendas func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { msg, err := s.ChannelMessageSend(command[1], command[2]) if err != nil { sendError(s, m.ChannelID, err) return } initNewEmbed(config.SuccessTitle, config.SendAsSuccessfulDescription, config.SuccessColour). AddField(config.SendAsSuccessfulMessageID, msg.ID). Send(s, m.ChannelID) }, )) var editAs = adminOnly(enforceArgumentCount(config.EditAsUsage, 4, //!editas func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { _, err := s.ChannelMessageEdit(command[1], command[2], command[3]) if err != nil { sendError(s, m.ChannelID, err) return } initNewEmbed(config.SuccessTitle, config.EditAsSuccessfulDescription, config.SuccessColour). Send(s, m.ChannelID) }, )) var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { if len(command) > 1 { value, err := backend.GetTrust(s, command[1]) if err != nil { sendError(s, m.ChannelID, err) return } total, err := backend.GetTotalTrust(s) if err != nil { sendError(s, m.ChannelID, err) return } newEmbed().SetColour(config.VTLColour). SetTitle(fmt.Sprintf(config.VTLSingleUserTitle, command[1], command[1])). AddField(config.VTLSingleUserValue, formatFloat(value, 1)). AddField(config.VTLSingleUserServerTotal, formatFloat(total, 1)). AddField(config.VTLSingleUserPercentage, formatFloat(value/total*100, 2)). Send(s, m.ChannelID) return } total, err := backend.GetTotalTrust(s) if err != nil { sendError(s, m.ChannelID, err) return } members, err := backend.GetAllMembers(s) if err != nil { sendError(s, m.ChannelID, err) return } //Generate message message := newEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle) for _, v := range members { value, err := backend.GetTrust(s, v.User.ID) if err == backend.ErrNotMember { continue } if err != nil { sendError(s, m.ChannelID, err) return } message.AddInlineField( v.User.Username+"#"+v.User.Discriminator, fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100), ) } message.Send(s, m.ChannelID) })