Only first bot connects when multiple are configured
Hi! I've followed the configuration and guide, and when I have one bot it works splendidly, we've had all sorts of fun with it, but when I have multiple bot_configs it appears that only the first one connects and relays messages. I've tried with the same account, different accounts, different channels, and whatever the first one to connect is succeeds while the rest do not.
In my Application.ex:
...
children = [
...
{PartitionSupervisor, child_spec: DynamicSupervisor, name: MyApp.DynamicSupervisors}
]
...
# Add the running ones
running_bots = MyApp.Context.Bot.get_all_running!()
bot_configs =
for bot <- running_bots do
# TMI bot config
[
bot: MyApp.Twitchbot,
user: bot.twitch_user,
pass: bot.twitch_pass,
channels: [bot.twitch_channel],
mod_channels: [""],
capabilities: ["membership", "tags", "commands"],
debug: false
]
end
for {bot_config, index} <- Enum.with_index(bot_configs) do
# give TMIs to supervisors
DynamicSupervisor.start_child(
{:via, PartitionSupervisor, {MyApp.DynamicSupervisors, index}},
{TMI.Supervisor, bot_config}
)
end
...
In Twitchbot.ex:
defmodule MyApp.Twitchbot do
use TMI
@impl TMI.Handler
def handle_message(message, sender, chat) do
Logger.debug("Message in #{chat} from #{sender}: #{message}")
end
end
...
I get Logger messages from the first bot to connect, and nothing else.
Snipped for relevance and also to remove a perhaps gratuitous amount of IO.inspect calls. Just trying to figure out what I've got set up incorrectly here, or what my fundamental misunderstanding is 😅
Thank you for your wonderful library!
I'll look into it at some point, but my guess is that it might be expecting a different module name per bot.
Okay, cool! I've been wondering how to handle having a user-configurable set of responses and behaviors etc per bot, which are currently defined by the implementation of MyApp.Twitchbot. Should I be thinking about how to somehow generate dynamic modules for each bot? Is there any way for the handler module to see what bot it's receiving events from?