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/db"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/server"
) )
var pendingInviteConfirmation = make(map[string]invite) 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, emojiFour)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiCheck) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiCheck)
server.VoteNotification()
} }

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

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

@ -9,6 +9,7 @@ import (
"TerraOceanBot/db" "TerraOceanBot/db"
"TerraOceanBot/discord/config" "TerraOceanBot/discord/config"
"TerraOceanBot/server"
) )
const ( 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, emojiThree)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFour) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFour)
s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive) s.MessageReactionAdd(config.VoteChannel, msg.ID, emojiFive)
server.VoteNotification()
default: default:
initNewEmbed( initNewEmbed(
config.VoteSuggestionErrorTitle, config.VoteSuggestionErrorTitle,

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