|
|
|
@ -2,86 +2,99 @@ package modules
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
|
|
|
|
|
"TerraOceanBot/discord/backend"
|
|
|
|
|
"TerraOceanBot/discord/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//adminID is my Discord user ID (chanbakjsd#7968).
|
|
|
|
|
const adminID = "218983355746746369"
|
|
|
|
|
|
|
|
|
|
func sendAs(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
|
func adminOnly(passOn CommandHandler) CommandHandler {
|
|
|
|
|
return func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
|
if m.Author.ID != adminID {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(command) < 3 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
message := strings.SplitN(m.Content, " ", 3)
|
|
|
|
|
msg, err := s.ChannelMessageSend(message[1], message[2])
|
|
|
|
|
if err != nil {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
passOn(s, m, command)
|
|
|
|
|
}
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "The message has been sent. Discord ID: "+msg.ID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func editAs(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
|
if m.Author.ID != adminID {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if len(command) < 4 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
message := strings.SplitN(m.Content, " ", 4)
|
|
|
|
|
_, err := s.ChannelMessageEdit(message[1], message[2], message[3])
|
|
|
|
|
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 {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
}
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "The message has been edited.")
|
|
|
|
|
sendError(s, m.ChannelID, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
initNewEmbed(config.SuccessTitle, config.SendAsSuccessfulDescription, config.SuccessColour).
|
|
|
|
|
AddField(config.SendAsSuccessfulMessageID, msg.ID).
|
|
|
|
|
Send(s, m.ChannelID)
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
func viewTrustLevel(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
|
if m.Author.ID != adminID {
|
|
|
|
|
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 {
|
|
|
|
|
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 {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
sendError(s, m.ChannelID, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
total, err := backend.GetTotalTrust(s)
|
|
|
|
|
if err != nil {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
sendError(s, m.ChannelID, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Trust level is %.1f/%.1f (%.2f%%) for user <@%d>.", value, total, value/total*100, command[1]))
|
|
|
|
|
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 {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
sendError(s, m.ChannelID, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
message := ""
|
|
|
|
|
members, err := backend.GetAllMembers(s)
|
|
|
|
|
if err != nil {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
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 {
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
|
sendError(s, m.ChannelID, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
message += fmt.Sprintf("%s#%s - %.1f/%.1f (%.2f%%)\n", v.User.Username, v.User.Discriminator, value, total, value/total*100)
|
|
|
|
|
}
|
|
|
|
|
s.ChannelMessageSend(m.ChannelID, message)
|
|
|
|
|
message.AddInlineField(
|
|
|
|
|
v.User.Username+"#"+v.User.Discriminator,
|
|
|
|
|
fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
message.Send(s, m.ChannelID)
|
|
|
|
|
})
|
|
|
|
|