refactor: Move realtime channels to its own config

This commit is contained in:
Matthew
2023-11-27 02:18:01 -05:00
parent 38b57c6d98
commit 523266fc68
4 changed files with 20 additions and 4 deletions

View File

@@ -75,7 +75,10 @@
"Discord": { "Discord": {
"Enabled": false, "Enabled": false,
"BotToken": "", "BotToken": "",
"RealtimeChannelID": "" "RealTimeChannel": {
"Enabled": false,
"RealTimeChannelID": ""
}
}, },
"Commands": [ "Commands": [
{ {

View File

@@ -161,8 +161,13 @@ type GameplayOptions struct {
// Discord holds the discord integration config. // Discord holds the discord integration config.
type Discord struct { type Discord struct {
Enabled bool
BotToken string
RealTimeChannel DiscordRealTime
}
type DiscordRealTime struct {
Enabled bool Enabled bool
BotToken string
RealtimeChannelID string RealtimeChannelID string
} }

View File

@@ -110,7 +110,7 @@ func (s *Server) onInteraction(ds *discordgo.Session, i *discordgo.InteractionCr
// 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.
if m.Author.Bot || m.ChannelID != s.erupeConfig.Discord.RealtimeChannelID { if m.Author.Bot || m.ChannelID != s.erupeConfig.Discord.RealTimeChannel.RealtimeChannelID {
return return
} }

View File

@@ -28,7 +28,11 @@ func NewDiscordBot(options Options) (discordBot *DiscordBot, err error) {
return nil, err return nil, err
} }
realtimeChannel, err := session.Channel(options.Config.Discord.RealtimeChannelID) var realtimeChannel *discordgo.Channel
if options.Config.Discord.RealTimeChannel.Enabled {
realtimeChannel, err = session.Channel(options.Config.Discord.RealTimeChannel.RealtimeChannelID)
}
if err != nil { if err != nil {
options.Logger.Fatal("Discord failed to create realtimeChannel", zap.Error(err)) options.Logger.Fatal("Discord failed to create realtimeChannel", zap.Error(err))
@@ -74,6 +78,10 @@ func (bot *DiscordBot) NormalizeDiscordMessage(message string) string {
} }
func (bot *DiscordBot) RealtimeChannelSend(message string) (err error) { func (bot *DiscordBot) RealtimeChannelSend(message string) (err error) {
if bot.RealtimeChannel == nil {
return
}
_, err = bot.Session.ChannelMessageSend(bot.RealtimeChannel.ID, message) _, err = bot.Session.ChannelMessageSend(bot.RealtimeChannel.ID, message)
return return