103 lines
2.9 KiB
Go
103 lines
2.9 KiB
Go
package modules
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
"TerraOceanBot/db"
|
|
"TerraOceanBot/discord/backend"
|
|
)
|
|
|
|
var trustMessage = make(map[string]string)
|
|
|
|
var changeTrust = enforceDM(memberFilter(true,
|
|
func(s *discordgo.Session, m *discordgo.MessageCreate, command []string) {
|
|
if len(command) < 2 {
|
|
s.ChannelMessageSend(m.ChannelID, "指令的使用方法是`!trust <你要改信任度的人>`.\nUsage: `!trust <the user>`")
|
|
return
|
|
}
|
|
|
|
member, err := backend.GetMemberFromUserFriendlyName(s, strings.SplitN(m.Content, " ", 2)[1])
|
|
if err == backend.ErrMemberNotFound {
|
|
s.ChannelMessageSend(m.ChannelID, "无法找到您所要求的玩家。\nCannot find the requested player.")
|
|
return
|
|
}
|
|
if err != nil {
|
|
auditError(s, m.ChannelID, err)
|
|
return
|
|
}
|
|
|
|
message, err := s.ChannelMessageSendEmbed(
|
|
m.ChannelID,
|
|
createTrustEmbed(member.User.Username+"#"+member.User.Discriminator, member.Nick),
|
|
)
|
|
if err != nil {
|
|
auditError(s, m.ChannelID, err)
|
|
return
|
|
}
|
|
|
|
trustMessage[message.ID] = member.User.ID
|
|
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiOne)
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiTwo)
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiThree)
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiFour)
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiFive)
|
|
s.MessageReactionAdd(m.ChannelID, message.ID, emojiCheck)
|
|
},
|
|
))
|
|
|
|
func createTrustEmbed(username, nick string) *discordgo.MessageEmbed {
|
|
embed := newEmbed().SetColour(0x00FFFF).SetTitle("更新玩家评分Update Player Score").AddField("ID", username)
|
|
if nick != "" {
|
|
embed.AddField("昵称Nickname", nick)
|
|
}
|
|
embed.AddField("提醒Reminder", "你一个月只能更换对一个玩家的评分一次。You can only change your trust towards a player once every month.")
|
|
return embed.Build()
|
|
}
|
|
|
|
func CheckForTrustUpdate(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
|
|
if r.UserID == s.State.User.ID {
|
|
return
|
|
}
|
|
target, ok := trustMessage[r.MessageID]
|
|
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
delete(trustMessage, r.MessageID)
|
|
|
|
var value int
|
|
switch r.Emoji.Name {
|
|
case emojiOne:
|
|
value = 1
|
|
case emojiTwo:
|
|
value = 2
|
|
case emojiThree:
|
|
value = 3
|
|
case emojiFour:
|
|
value = 4
|
|
case emojiFive:
|
|
value = 5
|
|
case emojiCheck:
|
|
value = db.NuclearOptionVote
|
|
default:
|
|
auditInfo(s, "Reaction "+r.Emoji.Name+" was added to trust message ID "+r.MessageID)
|
|
return
|
|
}
|
|
|
|
err := backend.UpdateTrust(r.UserID, target, value)
|
|
if err == db.ErrRecentlyChanged {
|
|
s.ChannelMessageSend(r.ChannelID, "你在一个月内有设定过该名玩家的分数。你这次的更动没有被记录。\nYou have changed your score for this player within the last month. Your change was not recorded.")
|
|
return
|
|
}
|
|
if err != nil {
|
|
auditError(s, r.ChannelID, err)
|
|
return
|
|
}
|
|
|
|
s.ChannelMessageSend(r.ChannelID, "已改变你给这名玩家的分数已被记录。\nThe score for this player has been updated.")
|
|
}
|