3 ms·
I recently used them to create a framework for handling plugins to an IRC bot. By creating an IrcMessageHandler metaclass, I can easily subclass it to encapsul
by Sohcahtoa82 5y ago
I recently used them to create a framework for handling plugins to an IRC bot.
By creating an IrcMessageHandler metaclass, I can easily subclass it to encapsulate functionality into different classes without having to add boilerplate to load each plugin. There's a Plugins directory with a __init__.py that automatically loads all .py files, and the main bot just has to do `from Plugins import *` to load them all. Each plugin script merely needs a `from ircbot import IrcMessageHandler`, then creates a subclass. So there's a Calc class that adds a "!calc" command, Seen class that adds "!seen", and more. Each of them merely needs to include an "on_message" function that parses IRC messages.