mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-12 23:14:36 +01:00
refactor: Move realtime channels to its own config
This commit is contained in:
@@ -75,7 +75,10 @@
|
|||||||
"Discord": {
|
"Discord": {
|
||||||
"Enabled": false,
|
"Enabled": false,
|
||||||
"BotToken": "",
|
"BotToken": "",
|
||||||
"RealtimeChannelID": ""
|
"RealTimeChannel": {
|
||||||
|
"Enabled": false,
|
||||||
|
"RealTimeChannelID": ""
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"Commands": [
|
"Commands": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user