-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add @at_start to trigger actions when plugins initialize fixes #132 * Stylize python code in documentation * Fix inconsistent indentation
- Loading branch information
Showing
5 changed files
with
77 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ Built-in decorators | |
=================== | ||
|
||
|
||
Allowed users:: | ||
Allowed users: | ||
|
||
.. code-block:: python | ||
from mmpy_bot.utils import allowed_users | ||
from mmpy_bot.bot import respond_to | ||
|
@@ -17,7 +19,9 @@ Allowed users:: | |
Direct messages:: | ||
Direct messages: | ||
|
||
.. code-block:: python | ||
from mmpy_bot.utils import allow_only_direct_message | ||
from mmpy_bot.bot import respond_to | ||
|
@@ -30,17 +34,34 @@ Direct messages:: | |
Actions just after plugin initilization: | ||
|
||
.. code-block:: python | ||
from mmpy_bot.bot import at_start | ||
@at_start | ||
def hello(client): | ||
client.connect_websocket() | ||
client.ping() | ||
Real case | ||
--------- | ||
|
||
For example we have some users on our chat. We want allow some functionality | ||
to some users. We can create constants with allowed users on bot settings:: | ||
to some users. We can create constants with allowed users on bot settings: | ||
|
||
.. code-block:: python | ||
ADMIN_USERS = ['admin', 'root', '[email protected]'] | ||
SUPPORT_USERS = ['mike', 'nick', '[email protected]'] | ||
So now we can close access to some functions on plugins:: | ||
So now we can close access to some functions on plugins: | ||
|
||
.. code-block:: python | ||
from mmpy_bot.utils import allow_only_direct_message | ||
from mmpy_bot.utils import allowed_users | ||
|
@@ -61,3 +82,10 @@ So now we can close access to some functions on plugins:: | |
def sms_to(message, name): | ||
# some code | ||
message.reply('Sms was sent to %s' % name) | ||
@at_start | ||
def hello(client): | ||
team = client.api.get_team_by_name("TESTTEAM") | ||
channel = client.api.get_channel_by_name("bot_test", team["id"]) | ||
client.channel_msg(channel["id"], "Hello, feels good to be alive!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters