ModuleBase
— Base class for Bot modules¶
All bot modules should extend this class. ModuleBase
includes helper methods
to integrate modules with the bot for smooth running.
-
class
pyircbot.modulebase.
AbstractHook
[source]¶ Bases:
object
Decorator for calling module methods in response to arbitrary IRC actions. Example:
@myhooksubclass(<conditions>) def mymyethod(self, message, extra): print("IRC server sent something that matched <conditions>")
This stores some record of the above filtering in an attribute of the decorated method, such as method.__tag_hooks. This attribute is scanned during module init and appropriate hooks are set up.
Hooks implement a validate() method that return a true-like or false-like item, dictating whether the hooked method will be called (with the message and true-like object as parameters)
Parameters: args (str) – irc protocol event to listen for. See pyircbot.irccore.IRCCore.initHooks()
for a complete list
-
exception
pyircbot.modulebase.
MissingDependancyException
[source]¶ Bases:
Exception
Exception expressing that a pyricbot module could not find a required module
-
class
pyircbot.modulebase.
ModuleBase
(bot, moduleName)[source]¶ Bases:
object
All modules will extend this class
Parameters: -
bot
= None¶ Reference to the master PyIRCBot object
-
config
= None¶ Configuration dictionary. Autoloaded from %(datadir)s/%(modulename)s.json
-
getFilePath
(f=None)[source]¶ Returns the absolute path to a file in this Module’s data dir
Parameters: f – The file name included in the path
Warning: Warning
this does no error checking if the file exists or is writable. The bot’s data dir should always be writable
-
irchooks
= None¶ IRC Hooks this module has
-
loadConfig
()[source]¶ Loads this module’s config into self.config. The bot’s main config is checked for a section matching the module name, which will be preferred. If not found, an individual config file will be loaded from the data dir
-
log
= None¶ Logger object for this module
-
moduleName
= None¶ Assigned name of this module
-
ondisable
()[source]¶ Called when the module should be disabled. Your module should do any sort of clean-up operations here like ending child threads or saving data files.
-
services
= None¶ If this module provides services usable by another module, they’re listed here
-
-
class
pyircbot.modulebase.
command
(*keywords, require_args=False, allow_private=False, allow_highlight=True)[source]¶ Bases:
pyircbot.modulebase.hook
Decorator for calling module methods when a command is parsed from chat
@command("ascii") def cmd_ascii(self, cmd, msg): print("Somebody typed .ascii with params {} in channel {}".format(str(cmd.args), msg.args[0]))
This stores a list of IRC actions each function is tagged for in method.__tag_commands. This attribute is scanned during module init and appropriate hooks are set up.
Parameters: - keywords (str) – commands to listen for
- require_args (bool, int) – only match if trailing data is passed with the command used. False-like values disable This requirement. True-like values require any number of args greater than one. Int values require a specific number of args
- allow_private (bool) – enable matching in private messages
- allow_highlight – treat ‘Nick[:,] command args’ the same as ‘.command args’
-
prefix
= '.'¶ Hotkey that must appear before commands
-
validate
(msg, bot)[source]¶ Test a message and return true if matched.
Parameters: - msg (pyircbot.irccore.IRCEvent) – message to test against
- bot (pyircbot.pyircbot.PyIRCBot) – reference to main pyircbot
-
class
pyircbot.modulebase.
hook
(*args)[source]¶ Bases:
pyircbot.modulebase.AbstractHook
Decorator for calling module methods in response to IRC actions. Example:
@hook("PRIVMSG") def mymyethod(self, message): print("IRC server sent PRIVMSG")
This stores a list of IRC actions each function is tagged for in method.__tag_hooks. This attribute is scanned during module init and appropriate hooks are set up.
Parameters: args (str) – irc protocol event to listen for. See pyircbot.irccore.IRCCore.initHooks()
for a complete list
-
class
pyircbot.modulebase.
regex
(*regexps, allow_private=False, types=None)[source]¶ Bases:
pyircbot.modulebase.hook
Decorator for calling module methods when a message matches a regex.
@regex(r'^foobar$') def cmd_foobar(self, matches, msg): print("Someone's message was exactly "foobar" ({}) in channel {}".format(msg.message, msg.args[0]))
Parameters: -
validate
(msg, bot)[source]¶ Test a message and return true if matched.
Parameters: - msg (pyircbot.irccore.IRCEvent) – message to test against
- bot (pyircbot.pyircbot.PyIRCBot) – reference to main pyircbot
-