mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-13 15:34:38 +01:00
support long messages, rename to RelayChannel, move commands out of main
This commit is contained in:
@@ -7,12 +7,39 @@ import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var Commands = []*discordgo.ApplicationCommand{
|
||||
{
|
||||
Name: "link",
|
||||
Description: "Link your Erupe account to Discord",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "token",
|
||||
Description: "The token provided by the Discord command in-game",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "password",
|
||||
Description: "Change your Erupe account password",
|
||||
Options: []*discordgo.ApplicationCommandOption{
|
||||
{
|
||||
Type: discordgo.ApplicationCommandOptionString,
|
||||
Name: "password",
|
||||
Description: "Your new password",
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
type DiscordBot struct {
|
||||
Session *discordgo.Session
|
||||
config *_config.Config
|
||||
logger *zap.Logger
|
||||
MainGuild *discordgo.Guild
|
||||
RealtimeChannel *discordgo.Channel
|
||||
Session *discordgo.Session
|
||||
config *_config.Config
|
||||
logger *zap.Logger
|
||||
MainGuild *discordgo.Guild
|
||||
RelayChannel *discordgo.Channel
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
@@ -28,22 +55,22 @@ func NewDiscordBot(options Options) (discordBot *DiscordBot, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var realtimeChannel *discordgo.Channel
|
||||
var relayChannel *discordgo.Channel
|
||||
|
||||
if options.Config.Discord.RealTimeChannel.Enabled {
|
||||
realtimeChannel, err = session.Channel(options.Config.Discord.RealTimeChannel.RealtimeChannelID)
|
||||
if options.Config.Discord.RelayChannel.Enabled {
|
||||
relayChannel, err = session.Channel(options.Config.Discord.RelayChannel.RelayChannelID)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
options.Logger.Fatal("Discord failed to create realtimeChannel", zap.Error(err))
|
||||
options.Logger.Fatal("Discord failed to create relayChannel", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
discordBot = &DiscordBot{
|
||||
config: options.Config,
|
||||
logger: options.Logger,
|
||||
Session: session,
|
||||
RealtimeChannel: realtimeChannel,
|
||||
config: options.Config,
|
||||
logger: options.Logger,
|
||||
Session: session,
|
||||
RelayChannel: relayChannel,
|
||||
}
|
||||
|
||||
return
|
||||
@@ -55,7 +82,7 @@ func (bot *DiscordBot) Start() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Replace all mentions to real name from the message.
|
||||
// NormalizeDiscordMessage replaces all mentions to real name from the message.
|
||||
func (bot *DiscordBot) NormalizeDiscordMessage(message string) string {
|
||||
userRegex := regexp.MustCompile(`<@!?(\d{17,19})>`)
|
||||
emojiRegex := regexp.MustCompile(`(?:<a?)?:(\w+):(?:\d{18}>)?`)
|
||||
@@ -78,11 +105,11 @@ func (bot *DiscordBot) NormalizeDiscordMessage(message string) string {
|
||||
}
|
||||
|
||||
func (bot *DiscordBot) RealtimeChannelSend(message string) (err error) {
|
||||
if bot.RealtimeChannel == nil {
|
||||
if bot.RelayChannel == nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = bot.Session.ChannelMessageSend(bot.RealtimeChannel.ID, message)
|
||||
_, err = bot.Session.ChannelMessageSend(bot.RelayChannel.ID, message)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user