-
Notifications
You must be signed in to change notification settings - Fork 26
Mods
Mods are reloadable modules the bot loads on start from the mods
folder
Mods are classes that are passed all events, like decorator event handler, but the difference is that mods are reloadable, and they can
contain extra data in self
since they are a custom class
to define a mod, create a python file in the mods
folder, the mods
folder can be found in the bot's working
directory AKA where it was started from
it should look like this:
mods
- mymod.py
in mods/mymod.py
create a class that imports and inherits the Mod
class
dont forget to set the mods name using name = 'NAME_HERE'
inside of the class
from twitchbot import Mod
class MyMod(Mod):
name = 'mymod'
Mods are passed the same events as decorator events, but are overriden a bit differently
mod events are overridden via standard method overriding in python by subclassing Mod
class
continuing the example above, lets handle privmsg_received
event and make the bot reply to "hello" messages
from twitchbot import Message, Mod
class MyMod(Mod):
name = 'mymod'
async def on_privmsg_received(self, msg: Message):
if 'hello' in msg.content:
await msg.reply(f'hello {msg.author}!')
all other events for mods can be seen by looking at the Mod source file
running the bot saying hello
in chat will now make the bot greet the user, example response:
john doe: hello bot
bot: hello john doe!
all events in mods are overriden in this fashion
mods have the unique events loaded
, unloaded
, on_enabled
and on_disabled
triggers when the mod is initially loaded, does not have any parameters
triggers when the mod is unloaded, does not have any parameters
triggers when the mod is enabled in a channel, gets passed the channels name as a string parameter
triggers when the mod is disabled in a channel, gets passed the channels name as a string parameter
mods can be reloaded using !reloadmod <mod name
, ex: !reloadmod mymod
,
the mod name after !reloadmod
has to match the mods name after name = ...
in the Mod's class