kritzware/twitch-bot

Dynamically adding and removing channels that a bot connects to?

Closed this issue · 5 comments

Hi there, I was wondering if this module helps satisfy the use case where you want to dynamically add or remove channel(s) that the bot is connected to.

I think currently, I would have to call close() on the bot which closes every channel and then instantiate another bot with the updated list of channels

Thats true, but its basically just implementing a PART-IRC-Message to allow "unsubscribing" from a channel:
https://dev.twitch.tv/docs/irc#part-generic

Overall the bot needs to provide two new functions: joinI(channelname) and part(channelname) that can be called during runtime.

As a workaround you can always use TwitchBotInstance.writeIrcMessage(text) in order to send commands that are currently not supported via specific functions even during runtime.

For example: writeIrcMessage("PART #sacriel") or writeIrcMessage("JOIN #sacriel").

As @anXieTyPB said above, a temporary fix would be to use the writeIrcMessage method, e.g.

Bot.writeIrcMessage("PART #channel") // Leaves the channel
Bot.writeIrcMessage("JOIN #channel") // Join a channel

Regarding new methods for the bot, such as joining/parting specific channels, I have some thoughts and ideas which I'll write here when I have some free time later 👍

https://github.com/anXieTyPB/twitch-bot/tree/dev-joinpart

Implemented the join() and part() functions. The join-event now emits with a string parameter that holds the channel name that was successfully joined.

Part-event with a string parameter that holds the channel name will be emitted aswell if user decides to part from a channel during runtime.

Also refactored redundant code and put the channelname validation into the parser file. Added tests for the features.

Currently updating the documentation is missing from the branch.

Great job @anXieTyPB
Can we allow TwitchBot to be initialized without specifying a list of channels now that we can fine-tune which channels to join and part after initialization? Maybe just default it to empty list if initial channels is not specified?

Should we also update this.channels whenever we join or part a channel?

EDIT: Moved this to comments on PR

Merged in 😄