go: Connect vote and username update to Kotlin plugin

pull/12/head
Luther Wen Xu 2019-10-13 19:48:24 +07:00
parent 69e2a2736c
commit d58e32f2b4
Signed by: chanbakjsd
GPG Key ID: B7D77E3E9D102B70
5 changed files with 26 additions and 0 deletions

@ -8,6 +8,7 @@ import (
"TerraOceanBot/db"
"TerraOceanBot/discord/config"
"TerraOceanBot/server"
)
var pendingInviteConfirmation = make(map[string]invite)
@ -175,4 +176,5 @@ func CheckForInvite(s *discordgo.Session, r *discordgo.MessageReactionAdd) {
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFour)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiCheck)
server.VoteNotification()
}

@ -4,7 +4,9 @@ import (
"github.com/bwmarrin/discordgo"
"TerraOceanBot/db"
"TerraOceanBot/discord/backend"
"TerraOceanBot/discord/config"
"TerraOceanBot/server"
)
var minecraftConfirmReact = make(map[string]string)
@ -66,6 +68,7 @@ func ConfirmMinecraftUsername(s *discordgo.Session, r *discordgo.MessageReaction
}
func processUsernameUpdate(s *discordgo.Session, discordID, channelID, newUsername string) {
oldUsername, oldErr := db.GetMinecraftUsername(discordID)
err := db.SetMinecraftUsername(discordID, newUsername)
if err == db.ErrAlreadyExists {
initNewEmbed(
@ -75,6 +78,12 @@ func processUsernameUpdate(s *discordgo.Session, discordID, channelID, newUserna
).Send(s, channelID)
return
}
backend.UpdateVoiceChannelState(s)
if oldErr == nil {
server.WhitelistRemove(oldUsername)
}
initNewEmbed(
config.SetMCUsernameSuccessTitle,
config.SetMCUsernameSuccessDescription,

@ -3,6 +3,7 @@ package modules
import "github.com/bwmarrin/discordgo"
type voteType struct {
//TODO Add FormatName(name string) to clean up vote name
EmbedBuilder func(id int, name string) *embed
ResultHandler func(s *discordgo.Session, id int, name string, isPositive bool)
}

@ -9,6 +9,7 @@ import (
"TerraOceanBot/db"
"TerraOceanBot/discord/config"
"TerraOceanBot/server"
)
const (
@ -132,6 +133,7 @@ func VoteSuggestion(s *discordgo.Session, m *discordgo.MessageCreate) {
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiThree)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFour)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive)
server.VoteNotification()
default:
initNewEmbed(
config.VoteSuggestionErrorTitle,

@ -50,3 +50,15 @@ func DisconnectUser(mcUsername string) {
func RequestSync() {
broadcast("sync")
}
func VoteNotification() {
broadcast("vote")
}
func WhitelistAdd(minecraftUsername string) {
broadcast("whitelistadd " + minecraftUsername)
}
func WhitelistRemove(minecraftUsername string) {
broadcast("whitelistremove " + minecraftUsername)
}