Allow for sending chats out from external chat submodule

This commit is contained in:
2023-06-17 23:33:35 +00:00
parent 77d41bb945
commit be07d4450a
4 changed files with 48 additions and 7 deletions

View File

@@ -62,6 +62,14 @@ func (app *Bot) Initialize(cfg *core.Config) error {
app.Session = discord.New(cfg.Discord.ApplicationID, app.guildID, cfg.Discord.Token, app.Database)
// Intialize submodules
for channelID, chats := range app.channelChats {
channel := app.Session.NewChannelFromID(channelID)
for _, chat := range chats {
app.InitalizeExternalChat(channel, chat)
}
}
// Register Event Handlers
app.Session.OnReady(app.onReady)
app.Session.OnEventCreate(app.onEventCreate)
@@ -167,8 +175,8 @@ func (app *Bot) onEventComplete(d *discord.Discord, event common.Event) {
}
func (app *Bot) onMessageRecieved(d *discord.Discord, channel string, user common.User, message string) {
chats, ok := app.channelChats[channel]
func (app *Bot) onMessageRecieved(d *discord.Discord, channelID string, user common.User, message string) {
chats, ok := app.channelChats[channelID]
if !ok {
return
}
@@ -181,6 +189,7 @@ func (app *Bot) onMessageRecieved(d *discord.Discord, channel string, user commo
// NewBot creates a new bot instance
func NewBot(db persistence.Database) *Bot {
return &Bot{
Database: db,
Database: db,
channelChats: make(map[string][]common.ExternalChatModule),
}
}