feat: Discord basic implementation

This commit is contained in:
Matthew
2023-11-26 01:22:51 -05:00
parent 7e5fd73496
commit 33665130cf
4 changed files with 48 additions and 0 deletions

View File

@@ -66,6 +66,27 @@ func getCharacterList(s *Server) string {
return message
}
// onInteraction handles slash commands
func (s *Server) onInteraction(ds *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.Interaction.ApplicationCommandData().Name {
case "verify":
_, err := s.db.Exec("UPDATE users SET discord_id = ? WHERE discord_token = ?", i.User.ID, i.Interaction.ApplicationCommandData().Options[0].StringValue())
if err != nil {
return
}
err = ds.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Account successfully linked",
},
})
if err != nil {
return
}
break
}
}
// onDiscordMessage handles receiving messages from discord and forwarding them ingame.
func (s *Server) onDiscordMessage(ds *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore messages from our bot, or ones that are not in the correct channel.