diff --git a/GoBot/discord/config/translate.go b/GoBot/discord/config/translate.go index 8394770..4e26dee 100644 --- a/GoBot/discord/config/translate.go +++ b/GoBot/discord/config/translate.go @@ -75,6 +75,8 @@ const VTLSingleUserServerTotal = "伺服器总分 Server Total" const VTLSingleUserPercentage = "百分比 Percentage" const VTLGlobalTitle = "伺服器信誉分报告 Server Trust Score Report" const VTLGlobalFieldFormat = "%.1f/%.1f (%.2f%%)" +const ErrorVTLTitle = "生成信誉分报告错误 Server Trust Score Report Generation Error" +const ErrorVTLTargetNotFound = "无法寻找到改变目标。\nCannot find the target user." const InviteUsage = "!invite <要制造的验证码>\n!invite " const InviteSuccessTitle = "制造验证码成功 Validation Code Creation Success" diff --git a/GoBot/discord/modules/admin.go b/GoBot/discord/modules/admin.go index 87f03f3..a261435 100644 --- a/GoBot/discord/modules/admin.go +++ b/GoBot/discord/modules/admin.go @@ -1,6 +1,9 @@ package modules import ( + "crypto/rand" + "crypto/sha512" + "encoding/hex" "fmt" "github.com/bwmarrin/discordgo" @@ -50,7 +53,16 @@ var editAs = adminOnly(enforceArgumentCount(config.EditAsUsage, 4, )) var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) { - if len(command) > 1 { + if len(command) > 1 && command[1] != "unobf" { + user, err := backend.GetMemberFromUserFriendlyName(s, command[1]) + if err != nil { + message.InitNewEmbed( + config.ErrorVTLTitle, + config.ErrorVTLTargetNotFound, + config.ErrorColour, + ).Send(s, m.ChannelID) + return + } value, err := backend.GetTrust(s, command[1]) if err != nil { message.AuditError(s, m.ChannelID, err) @@ -81,6 +93,9 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr return } + salt := make([]byte, 16) + rand.Read(salt) + //Generate message msg := message.NewEmbed().SetColour(config.VTLColour).SetTitle(config.VTLGlobalTitle) for _, v := range members { @@ -92,12 +107,27 @@ var viewTrustLevel = adminOnly(func(s *discordgo.Session, m *discordgo.MessageCr message.AuditError(s, m.ChannelID, err) return } + var username string + if len(command) > 1 { + username = v.User.Username + "#" + v.User.Discriminator + } else { + saltedUsername := []byte(v.User.Username + "#" + v.User.Discriminator) + saltedUsername = append(saltedUsername, salt...) + username = hex.EncodeToString(sha512.New().Sum(saltedUsername))[:64] + if username == "" { + username = "" + } + } msg.AddInlineField( - v.User.Username+"#"+v.User.Discriminator, + username, fmt.Sprintf(config.VTLGlobalFieldFormat, value, total, value/total*100), ) } - msg.Send(s, m.ChannelID) + _, err = msg.Send(s, m.ChannelID) + if err != nil { + message.AuditError(s, m.ChannelID, err) + return + } }) var batchGiveRole = adminOnly(enforceDM(enforceArgumentCount(