| 1 |
Mentions |
| 2 |
======== |
| 3 |
|
| 4 |
Depending on the backend used, users can mention and notify other users by using a special syntax like `@gbin`. |
| 5 |
With this feature, a plugin can listen to the mentioned users in the chat. |
| 6 |
|
| 7 |
How to use it |
| 8 |
------------- |
| 9 |
|
| 10 |
Here is an example to listen to every mention and report them back on the chat. |
| 11 |
|
| 12 |
.. code-block:: python |
| 13 |
|
| 14 |
from errbot import BotPlugin |
| 15 |
|
| 16 |
class PluginExample(BotPlugin): |
| 17 |
|
| 18 |
def callback_mention(self, message, mentioned_people): |
| 19 |
for identifier in mentioned_people: |
| 20 |
self.send(message.frm, 'User %s has been mentioned' % identifier) |
| 21 |
|
| 22 |
|
| 23 |
Identifying if the bot itself has been mentioned |
| 24 |
------------------------------------------------ |
| 25 |
|
| 26 |
Simply test the presence of the bot identifier within the `mentioned_people`: |
| 27 |
|
| 28 |
.. code-block:: python |
| 29 |
|
| 30 |
from errbot import BotPlugin |
| 31 |
|
| 32 |
class PluginExample(BotPlugin): |
| 33 |
|
| 34 |
def callback_mention(self, message, mentioned_people): |
| 35 |
if self.bot_identifier in mentioned_people: |
| 36 |
self.send(message.frm, 'Errbot has been mentioned !') |
| 37 |
|