2019-10-12 09:45:43 +07:00
|
|
|
package modules
|
2019-10-09 12:44:43 +07:00
|
|
|
|
|
|
|
import (
|
2019-10-11 15:13:57 +07:00
|
|
|
"fmt"
|
2019-10-09 12:44:43 +07:00
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
2019-10-12 09:45:43 +07:00
|
|
|
|
|
|
|
"TerraOceanBot/discord/backend"
|
2019-10-12 11:29:33 +07:00
|
|
|
"TerraOceanBot/discord/config"
|
2019-10-13 12:38:00 +07:00
|
|
|
"TerraOceanBot/discord/message"
|
2019-10-09 12:44:43 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
//adminID is my Discord user ID (chanbakjsd#7968).
|
|
|
|
const adminID = "218983355746746369"
|
|
|
|
|
2019-10-12 11:29:33 +07:00
|
|
|
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)
|
2019-10-09 12:44:43 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-12 11:29:33 +07:00
|
|
|
var sendAs = adminOnly(enforceArgumentCount(config.SendAsUsage, 3,
|
|
|
|
//!sendas <channel ID> <message>
|
|
|
|
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
msg, err := s.ChannelMessageSend(command[1], command[2])
|
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-12 11:29:33 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.SuccessTitle, config.SendAsSuccessfulDescription, config.SuccessColour).
|
2019-10-12 11:29:33 +07:00
|
|
|
AddField(config.SendAsSuccessfulMessageID, msg.ID).
|
|
|
|
Send(s, m.ChannelID)
|
|
|
|
},
|
|
|
|
))
|
2019-10-11 15:13:57 +07:00
|
|
|
|
2019-10-12 11:29:33 +07:00
|
|
|
var editAs = adminOnly(enforceArgumentCount(config.EditAsUsage, 4,
|
|
|
|
//!editas <channel ID> <message ID> <message>
|
|
|
|
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
_, err := s.ChannelMessageEdit(command[1], command[2], command[3])
|
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-12 11:29:33 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-13 12:38:00 +07:00
|
|
|
message.InitNewEmbed(config.SuccessTitle, config.EditAsSuccessfulDescription, config.SuccessColour).
|
2019-10-12 11:29:33 +07:00
|
|
|
Send(s, m.ChannelID)
|
|
|
|
},
|
|
|
|
))
|
|
|
|
|
|
|
|
var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
2019-10-11 15:13:57 +07:00
|
|
|
if len(command) > 1 {
|
2019-10-12 09:45:43 +07:00
|
|
|
value, err := backend.GetTrust(s, command[1])
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-12 09:45:43 +07:00
|
|
|
total, err := backend.GetTotalTrust(s)
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-13 12:38:00 +07:00
|
|
|
message.NewEmbed().SetColour(config.VTLColour).
|
2019-10-12 11:29:33 +07:00
|
|
|
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)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-12 09:45:43 +07:00
|
|
|
total, err := backend.GetTotalTrust(s)
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-12 09:45:43 +07:00
|
|
|
members, err := backend.GetAllMembers(s)
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-12 11:29:33 +07:00
|
|
|
|
|
|
|
//Generate message
|
2019-10-13 12:38:00 +07:00
|
|
|
msg := message.NewEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle)
|
2019-10-11 15:13:57 +07:00
|
|
|
for _, v := range members {
|
2019-10-12 09:45:43 +07:00
|
|
|
value, err := backend.GetTrust(s, v.User.ID)
|
|
|
|
if err == backend.ErrNotMember {
|
2019-10-11 15:20:12 +07:00
|
|
|
continue
|
|
|
|
}
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
2019-10-13 12:38:00 +07:00
|
|
|
message.AuditError(s, m.ChannelID, err)
|
2019-10-11 15:13:57 +07:00
|
|
|
return
|
|
|
|
}
|
2019-10-13 12:38:00 +07:00
|
|
|
msg.AddInlineField(
|
2019-10-12 11:29:33 +07:00
|
|
|
v.User.Username+"#"+v.User.Discriminator,
|
|
|
|
fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100),
|
|
|
|
)
|
2019-10-11 15:13:57 +07:00
|
|
|
}
|
2019-10-13 12:38:00 +07:00
|
|
|
msg.Send(s, m.ChannelID)
|
2019-10-12 11:29:33 +07:00
|
|
|
})
|
2019-10-15 11:01:36 +07:00
|
|
|
|
|
|
|
var batchGiveRole = adminOnly(enforceDM(enforceArgumentCount(
|
|
|
|
config.BatchRoleUsage, 2,
|
|
|
|
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
members, err := backend.GetAllMembers(s)
|
|
|
|
if err != nil {
|
|
|
|
message.AuditError(s, m.ChannelID, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, member := range members {
|
|
|
|
err := s.GuildMemberRoleAdd(
|
|
|
|
config.GuildID,
|
|
|
|
member.User.ID,
|
|
|
|
command[1],
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
message.AuditError(s, m.ChannelID, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message.InitNewEmbed(config.SuccessTitle, config.BatchRoleSuccessMessage, config.SuccessColour).
|
|
|
|
Send(s, m.ChannelID)
|
|
|
|
},
|
|
|
|
)))
|