mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
feat: Discord basic implementation
This commit is contained in:
6
patch-schema/15-discord-password-resets.sql
Normal file
6
patch-schema/15-discord-password-resets.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
BEGIN;
|
||||||
|
|
||||||
|
ALTER TABLE IF EXISTS public.users ADD COLUMN discord_token text;
|
||||||
|
ALTER TABLE IF EXISTS public.users ADD COLUMN discord_id text;
|
||||||
|
|
||||||
|
END;
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package channelserver
|
package channelserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"erupe-ce/common/byteframe"
|
"erupe-ce/common/byteframe"
|
||||||
"erupe-ce/common/mhfcourse"
|
"erupe-ce/common/mhfcourse"
|
||||||
@@ -318,6 +319,15 @@ func parseChatCommand(s *Session, command string) {
|
|||||||
} else {
|
} else {
|
||||||
sendDisabledCommandMessage(s, commands["Teleport"])
|
sendDisabledCommandMessage(s, commands["Teleport"])
|
||||||
}
|
}
|
||||||
|
case commands["Discord"].Prefix:
|
||||||
|
if commands["Discord"].Enabled {
|
||||||
|
token := crypto.MD5.New()
|
||||||
|
_, err := s.server.db.Exec("UPDATE users SET discord_token = ?", token)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendServerChatMessage(s, fmt.Sprintf(s.server.dict["commandDiscord"], token))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,27 @@ func getCharacterList(s *Server) string {
|
|||||||
return message
|
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.
|
// onDiscordMessage handles receiving messages from discord and forwarding them ingame.
|
||||||
func (s *Server) onDiscordMessage(ds *discordgo.Session, m *discordgo.MessageCreate) {
|
func (s *Server) onDiscordMessage(ds *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
// Ignore messages from our bot, or ones that are not in the correct channel.
|
// Ignore messages from our bot, or ones that are not in the correct channel.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package channelserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -210,7 +211,17 @@ func (s *Server) Start() error {
|
|||||||
|
|
||||||
// Start the discord bot for chat integration.
|
// Start the discord bot for chat integration.
|
||||||
if s.erupeConfig.Discord.Enabled && s.discordBot != nil {
|
if s.erupeConfig.Discord.Enabled && s.discordBot != nil {
|
||||||
|
_, err := s.discordBot.Session.ApplicationCommandBulkOverwrite(s.discordBot.Session.State.User.ID, "", []*discordgo.ApplicationCommand{
|
||||||
|
{
|
||||||
|
Name: "verify",
|
||||||
|
Description: "Verify your account with Discord",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
s.discordBot.Session.AddHandler(s.onDiscordMessage)
|
s.discordBot.Session.AddHandler(s.onDiscordMessage)
|
||||||
|
s.discordBot.Session.AddHandler(s.onInteraction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user