From 55192d4928ca9fe3d8a950907f66aee15b74cbbc Mon Sep 17 00:00:00 2001 From: dpedu Date: Sat, 8 Aug 2015 16:50:26 -0700 Subject: [PATCH] More docs --- docs/module_guide/_module_guide.rst | 31 ++++++++++++++++++++++++++-- examples/data/modules/EchoExample.py | 14 +++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 examples/data/modules/EchoExample.py diff --git a/docs/module_guide/_module_guide.rst b/docs/module_guide/_module_guide.rst index 5d0b22e..4bbb8f1 100644 --- a/docs/module_guide/_module_guide.rst +++ b/docs/module_guide/_module_guide.rst @@ -24,7 +24,7 @@ modules one after the other so a long delay slows bot startup. .. code-block:: python def __init__(self, bot, moduleName): - ModuleBase.__init__(self, bot, moduleName); + ModuleBase.__init__(self, bot, moduleName) If your module has a config file - EchoExample.json - it can be loaded by calling :py:meth:`pyircbot.modulebase.ModuleBase.loadConfig`: @@ -74,6 +74,33 @@ shutdown handler is needed to ensure a clean shutdown. """ pass +EchoExample module +------------------ + +.. code-block:: python + + from pyircbot.modulebase import ModuleBase,ModuleHook + + class EchoExample(ModuleBase): + def __init__(self, bot, moduleName): + ModuleBase.__init__(self, bot, moduleName) + self.loadConfig() + print(self.config) + self.hooks=[ModuleHook("PRIVMSG", self.echo)] + + def echo(self, args, prefix, trailing): + self.bot.act_PRIVMSG(args[0], trailing) + + def ondisable(self): + print("I'm getting unloaded!") + +In usage: + +.. code-block:: text + + 4:40:17 PM test + 4:40:17 PM test + Advanced Usage ============== @@ -105,7 +132,7 @@ Modules providing a service state so like: .. code-block:: python def __init__(self, bot, moduleName): - ModuleBase.__init__(self, bot, moduleName); + ModuleBase.__init__(self, bot, moduleName) self.services=["cache"] Then, another module can find this one by using either diff --git a/examples/data/modules/EchoExample.py b/examples/data/modules/EchoExample.py new file mode 100644 index 0000000..ebb65cb --- /dev/null +++ b/examples/data/modules/EchoExample.py @@ -0,0 +1,14 @@ +from pyircbot.modulebase import ModuleBase,ModuleHook + +class EchoExample(ModuleBase): + def __init__(self, bot, moduleName): + ModuleBase.__init__(self, bot, moduleName) + self.loadConfig() + print(self.config) + self.hooks=[ModuleHook("PRIVMSG", self.echo)] + + def echo(self, args, prefix, trailing): + self.bot.act_PRIVMSG(args[0], trailing) + + def ondisable(self): + print("I'm getting unloaded!") \ No newline at end of file