go: discord/modules: Obfuscate username by default

This allows me to view trust level report without actually knowing the trust level of everyone
Luther Wen Xu 2019-10-19 22:47:39 +07:00
parent ddb7877fca
commit 5b33e20640
Signed by untrusted user: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
2 changed files with 35 additions and 3 deletions

@ -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 <validation code to create>"
const InviteSuccessTitle = "制造验证码成功 Validation Code Creation Success"

@ -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 = "<cannot calculate hash>"
}
}
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(