Debian Codegraph @

docs/user_guide/plugin_development/presence.rst

raw
1 Presence
2 ========
3
4 Presence describes the concept of a person's availability state, such as
5 *online* or *away*, possibly with an optional message.
6
7
8 Callbacks for presence changes
9 ------------------------------
10
11 Plugins may override :meth:`~errbot.botplugin.BotPlugin.callback_presence`
12 in order to receive notifications of presence changes. You will receive
13 a :class:`~errbot.backends.base.Presence` object for every presence change
14 received by Errbot.
15
16 Here's an example which simply logs each presence change to the log
17 when it includes a status message:
18
19 .. code-block:: python
20
21 from errbot import BotPlugin
22
23 class PluginExample(BotPlugin):
24 def callback_presence(self, presence):
25 if presence.get_message() is not None:
26 self.log.info(presence)
27
28 Change the presence or status of the bot
29 ----------------------------------------
30
31 You can also, depending on the backend you use, change the current status of
32 the bot. This allows you to make a moody bot that leaves the room when it is
33 in a bad mood ;)
34
35
36 .. code-block:: python
37
38 from errbot import BotPlugin, botcmd, ONLINE, AWAY
39
40 class PluginExample(BotPlugin):
41 @botcmd
42 def grumpy(self, mess, args):
43 self.change_presence(AWAY, 'I am tired of you all!')
44
45 @botcmd
46 def happy(self, mess, args):
47 self.change_presence(ONLINE, 'I am back and so happy to see you!')
48
49