TerraOceanPlugin/GoBot/vote.go

63 lines
1.5 KiB
Go

package main
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
func checkForVote(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
voteID, err := getVoteFromMessageID(r.MessageID)
if err != nil {
return
}
s.MessageReactionRemove(r.ChannelID, r.MessageID, r.Emoji.ID, r.UserID)
var value int
switch r.Emoji.Name {
case "x":
value = forceRejectionVote
case "one":
value = 1
case "two":
value = 2
case "three":
value = 3
case "four":
value = 4
case "five":
value = 5
case "white_check_mark":
value = nuclearOptionVote
default:
return
}
err = updateVote(voteID, r.UserID, value)
if err == errForceRejectionVoteReuse {
sendPrivateMessage(s, r.UserID, "您在这个月内已使用过:x:。请选择其他选项。\nYou have used :x: this month. Please choose another option.")
return
}
if err == errVoteIsOver {
sendPrivateMessage(s, r.UserID, "这个投票已结束。你投的票没有被记录。\nThe vote is over so your vote is not recorded.")
return
}
var voteName string
if err == nil {
voteName, err = getVoteName(voteID)
}
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()),
)
return
}
sendPrivateMessage(s, r.UserID, "您投票已成功。\nYou have voted successfully.\n名字Vote Name: "+voteName+"\n目前投的票 :"+r.Emoji.Name+":")
}