a lot of stuff in here around support for loading plugins from arbitrary files. plugins have a basic amount of initialization and then hook into the core IRC event system it makes sense to have modules respond to regexes, so there's some handler stuff for that --- it was the most popular way to do stuff in the old version of the bot we need to check that people trying to load plugins are admins, so there's some stuff for that, too the expectation is that many features from here are happen in plugins, rather than modifying the core bot
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""Library and convenience methods for the IRC bot and plugins."""
|
|
|
|
import logging
|
|
|
|
from ircbot.models import BotAdmin
|
|
|
|
|
|
log = logging.getLogger('ircbot.lib')
|
|
|
|
|
|
class Plugin(object):
|
|
|
|
"""Plugin base class."""
|
|
|
|
def __init__(self, bot, connection, event):
|
|
"""Initialization stuff here --- global handlers, configs from database, so on."""
|
|
|
|
self.bot = bot
|
|
self.connection = connection
|
|
self.event = event
|
|
|
|
log.info(u"initialized %s", self.__class__.__name__)
|
|
|
|
def start(self):
|
|
"""Initialization stuff here --- global handlers, configs from database, so on."""
|
|
|
|
log.info(u"started %s", self.__class__.__name__)
|
|
|
|
def stop(self):
|
|
"""Teardown stuff here --- unregister handlers, for example."""
|
|
|
|
log.info(u"stopped %s", self.__class__.__name__)
|
|
|
|
|
|
def is_admin(source):
|
|
"""Check if the provided event source is a bot admin."""
|
|
|
|
if source in BotAdmin.objects.values_list('nickmask', flat=True):
|
|
log.debug(u"in is_admin; True")
|
|
return True
|
|
log.debug(u"in is_admin; False")
|
|
return False
|