2019-10-09 12:44:43 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-11 15:13:57 +07:00
|
|
|
"fmt"
|
2019-10-09 12:44:43 +07:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
)
|
|
|
|
|
|
|
|
//adminID is my Discord user ID (chanbakjsd#7968).
|
|
|
|
const adminID = "218983355746746369"
|
|
|
|
|
|
|
|
func sendAs(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())
|
|
|
|
}
|
|
|
|
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])
|
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
}
|
|
|
|
s.ChannelMessageSend(m.ChannelID, "The message has been edited.")
|
|
|
|
}
|
2019-10-11 15:13:57 +07:00
|
|
|
|
|
|
|
func viewTrustLevel(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
|
|
if m.Author.ID != adminID {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(command) > 1 {
|
2019-10-11 15:20:12 +07:00
|
|
|
value, err := getTrust(s, command[1])
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
total, err := getTotalTrust(s)
|
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("Trust level is %.1f/%.1f (%.2f%%) for user <@%d>.", value, total, value/total*100, command[1]))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
total, err := getTotalTrust(s)
|
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
message := ""
|
|
|
|
members, err := getAllMembers(s)
|
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, v := range members {
|
2019-10-11 15:20:12 +07:00
|
|
|
value, err := getTrust(s, v.User.ID)
|
|
|
|
if err == errNotMember {
|
|
|
|
continue
|
|
|
|
}
|
2019-10-11 15:13:57 +07:00
|
|
|
if err != nil {
|
|
|
|
s.ChannelMessageSend(m.ChannelID, err.Error())
|
|
|
|
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)
|
|
|
|
}
|