2013-04-08 16:52:35 +00:00
|
|
|
Plugin API documentation
|
|
|
|
========================
|
|
|
|
|
2013-04-13 20:56:00 +00:00
|
|
|
BasePlugin
|
|
|
|
----------
|
|
|
|
|
2013-04-08 16:52:35 +00:00
|
|
|
.. module:: plugin
|
|
|
|
|
|
|
|
.. autoclass:: BasePlugin
|
|
|
|
:members: init, cleanup, api, core
|
|
|
|
|
|
|
|
.. method:: init(self)
|
|
|
|
|
|
|
|
Method called at the creation of the plugin.
|
|
|
|
|
|
|
|
Do not override __init__ and use this instead.
|
|
|
|
|
|
|
|
.. method:: cleanup(self)
|
|
|
|
|
|
|
|
Method called before the destruction of the plugin.
|
|
|
|
|
|
|
|
Use it to erase or save things before the plugin is disabled.
|
|
|
|
|
|
|
|
.. attribute:: core
|
|
|
|
|
|
|
|
The Poezio :py:class:`~Core` object. Use it carefully.
|
|
|
|
|
|
|
|
.. attribute:: api
|
|
|
|
|
|
|
|
The :py:class:`~PluginAPI` instance for this plugin.
|
|
|
|
|
|
|
|
|
|
|
|
Each plugin inheriting :py:class:`~BasePlugin` has an ``api`` member variable, which refers
|
|
|
|
to a :py:class:`~PluginAPI` object.
|
|
|
|
|
|
|
|
The :py:class:`~PluginAPI` object is an a interface through which the :py:class:`~BasePlugin`
|
|
|
|
(and inheritors) *should* go to interact with poezio. If it is not sufficient, then the ``core``
|
|
|
|
member can be used.
|
|
|
|
|
2013-04-13 20:56:00 +00:00
|
|
|
PluginAPI
|
|
|
|
---------
|
|
|
|
|
2013-04-08 16:52:35 +00:00
|
|
|
.. autoclass:: PluginAPI
|
|
|
|
:members:
|
|
|
|
:undoc-members:
|
|
|
|
|
|
|
|
|
2013-04-13 20:56:00 +00:00
|
|
|
Example plugins
|
|
|
|
---------------
|
|
|
|
|
|
|
|
**Example 1:** Add a simple command that sends "Hello World!" into the conversation
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
|
|
|
self.add_command('hello', self.command_hello, "Send 'Hello World!'")
|
|
|
|
|
|
|
|
def command_hello(self, arg):
|
|
|
|
self.core.send_message('Hello World!')
|
|
|
|
|
|
|
|
**Example 2:** Adds an event handler that sends “tg” to a groupchat when a message is received from someone named “Partauche”
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
class Plugin(BasePlugin):
|
|
|
|
def init(self):
|
|
|
|
self.add_event_handler('muc_msg', self.on_groupchat_message)
|
|
|
|
|
|
|
|
def on_groupchat_message(self, message, tab):
|
|
|
|
if message['mucnick'] == "Partauche":
|
|
|
|
tab.command_say('tg')
|