|
|
|
@ -2,35 +2,57 @@ package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const voteChannel = "627164246056239104"
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
emojiOne = "1⃣"
|
|
|
|
|
emojiTwo = "2⃣"
|
|
|
|
|
emojiThree = "3⃣"
|
|
|
|
|
emojiFour = "4⃣"
|
|
|
|
|
emojiFive = "5⃣"
|
|
|
|
|
emojiCheck = "✅"
|
|
|
|
|
emojiX = "❌"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func checkForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
|
|
|
|
|
if r.UserID == s.State.User.ID {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
voteID, err := getVoteFromMessageID(r.MessageID)
|
|
|
|
|
if err == errNotFound {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
auditLog(s, "Error while checking for vote: "+err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s.MessageReactionRemove(r.ChannelID, r.MessageID, r.Emoji.ID, r.UserID)
|
|
|
|
|
s.MessageReactionRemove(r.ChannelID, r.MessageID, r.Emoji.Name, r.UserID)
|
|
|
|
|
|
|
|
|
|
var value int
|
|
|
|
|
switch r.Emoji.Name {
|
|
|
|
|
case "x":
|
|
|
|
|
case emojiX:
|
|
|
|
|
value = forceRejectionVote
|
|
|
|
|
case "one":
|
|
|
|
|
case emojiOne:
|
|
|
|
|
value = 1
|
|
|
|
|
case "two":
|
|
|
|
|
case emojiTwo:
|
|
|
|
|
value = 2
|
|
|
|
|
case "three":
|
|
|
|
|
case emojiThree:
|
|
|
|
|
value = 3
|
|
|
|
|
case "four":
|
|
|
|
|
case emojiFour:
|
|
|
|
|
value = 4
|
|
|
|
|
case "five":
|
|
|
|
|
case emojiFive:
|
|
|
|
|
value = 5
|
|
|
|
|
case "white_check_mark":
|
|
|
|
|
case emojiCheck:
|
|
|
|
|
value = nuclearOptionVote
|
|
|
|
|
default:
|
|
|
|
|
auditLog(s, "Reaction "+r.Emoji.Name+" was added to vote #"+strconv.Itoa(voteID))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,10 +75,53 @@ func checkForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
sendPrivateMessage(s, r.UserID, "一个错误已发生,请重新尝试。\nAn error has occurred while voting. Please try again.")
|
|
|
|
|
auditLog(s,
|
|
|
|
|
fmt.Sprintf("Error occurred while processing vote for <@%s>.\n%v\nError: %s", r.UserID, r, err.Error()),
|
|
|
|
|
fmt.Sprintf("Error occurred while processing vote for <@%s>.\n%v\nError: %s", r.UserID, *r, err.Error()),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sendPrivateMessage(s, r.UserID, "您投票已成功。\nYou have voted successfully.\n名字Vote Name: "+voteName+"\n目前投的票: :"+r.Emoji.Name+":")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func voteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
|
|
|
|
|
s.ChannelMessageDelete(m.ChannelID, m.ID)
|
|
|
|
|
|
|
|
|
|
args := strings.SplitN(m.Content, " ", 2)
|
|
|
|
|
if len(args) == 1 {
|
|
|
|
|
sendPrivateMessage(s, m.Author.ID, "请提供更多资料。\nPlease provide more information.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch args[0] {
|
|
|
|
|
case "custom":
|
|
|
|
|
msg, err := s.ChannelMessageSend(voteChannel, "正在准备新的一个投票…… Preparing for the next vote...")
|
|
|
|
|
if err != nil {
|
|
|
|
|
sendPrivateMessage(s, m.Author.ID, "创造投票失败。Failed to create vote.")
|
|
|
|
|
auditLog(s,
|
|
|
|
|
fmt.Sprintf("Error occurred while creating vote for <@%s>.\n%v\nError: %s", m.Author.ID, *m, err.Error()),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
id, err := createCustomVote(msg.ID, args[1])
|
|
|
|
|
if err != nil {
|
|
|
|
|
sendPrivateMessage(s, m.Author.ID, "创造投票失败。Failed to create vote.")
|
|
|
|
|
auditLog(s,
|
|
|
|
|
fmt.Sprintf("Error occurred while creating vote for <@%s>.\n%v\nError: %s", m.Author.ID, *m, err.Error()),
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
auditLog(s, fmt.Sprintf("Vote ID %d has been created by <@%s>.", id, m.Author.ID))
|
|
|
|
|
s.ChannelMessageEdit(voteChannel, msg.ID, "")
|
|
|
|
|
s.ChannelMessageEditEmbed(
|
|
|
|
|
voteChannel, msg.ID,
|
|
|
|
|
newEmbed().SetColour(0x00FFFF).SetTitle("自定义投票Custom Vote").AddField("ID", strconv.Itoa(id)).AddField("内容Content", args[1]).Build(),
|
|
|
|
|
)
|
|
|
|
|
s.MessageReactionAdd(voteChannel, msg.ID, emojiOne)
|
|
|
|
|
s.MessageReactionAdd(voteChannel, msg.ID, emojiTwo)
|
|
|
|
|
s.MessageReactionAdd(voteChannel, msg.ID, emojiThree)
|
|
|
|
|
s.MessageReactionAdd(voteChannel, msg.ID, emojiFour)
|
|
|
|
|
s.MessageReactionAdd(voteChannel, msg.ID, emojiFive)
|
|
|
|
|
default:
|
|
|
|
|
sendPrivateMessage(s, m.Author.ID, "未知投票种类:"+args[0]+"\nUnknown vote type: "+args[0])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|