File: presence.rst

package info (click to toggle)
errbot 6.2.0%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,796 kB
  • sloc: python: 11,557; makefile: 164; sh: 97
file content (49 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Presence
========

Presence describes the concept of a person's availability state, such as
*online* or *away*, possibly with an optional message.


Callbacks for presence changes
------------------------------

Plugins may override :meth:`~errbot.botplugin.BotPlugin.callback_presence`
in order to receive notifications of presence changes. You will receive
a :class:`~errbot.backends.base.Presence` object for every presence change
received by Errbot.

Here's an example which simply logs each presence change to the log
when it includes a status message:

.. code-block:: python

    from errbot import BotPlugin

    class PluginExample(BotPlugin):
        def callback_presence(self, presence):
            if presence.get_message() is not None:
                self.log.info(presence)

Change the presence or status of the bot
----------------------------------------

You can also, depending on the backend you use, change the current status of
the bot. This allows you to make a moody bot that leaves the room when it is
in a bad mood ;)


.. code-block:: python

    from errbot import BotPlugin, botcmd, ONLINE, AWAY

    class PluginExample(BotPlugin):
        @botcmd
        def grumpy(self, mess, args):
            self.change_presence(AWAY, 'I am tired of you all!')

        @botcmd
        def happy(self, mess, args):
            self.change_presence(ONLINE, 'I am back and so happy to see you!')