forked from attzonko/mmpy_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
70 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.. _decorators: | ||
|
||
Builtin decorators | ||
================== | ||
|
||
|
||
Allowed users:: | ||
|
||
from mattermost_bot.utils import allowed_users | ||
from mattermost_bot.bot import respond_to | ||
|
||
|
||
@respond_to('^is-allowed$') | ||
@allowed_users('admin', 'root') | ||
def access_allowed(message): | ||
message.reply('Access is allowed') | ||
|
||
|
||
|
||
Direct messages:: | ||
|
||
from mattermost_bot.utils import allow_only_direct_message | ||
from mattermost_bot.bot import respond_to | ||
|
||
|
||
@respond_to('^direct-msg$') | ||
@allow_only_direct_message() | ||
def direct_msg(message): | ||
message.reply('Message is direct') | ||
|
||
|
||
|
||
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:: | ||
|
||
ADMIN_USERS = ['admin', 'root'] | ||
SUPPORT_USERS = ['mike', 'nick'] | ||
|
||
|
||
So now we can close access to some functions on plugins:: | ||
|
||
from mattermost_bot.utils import allow_only_direct_message | ||
from mattermost_bot.utils import allowed_users | ||
from mattermost_bot.bot import respond_to | ||
from mattermost_bot import settings | ||
|
||
|
||
@respond_to('^selfupdate') | ||
@allow_only_direct_message() | ||
@allowed_users(*settings.ADMIN_USERS) | ||
def self_update(message): | ||
# some code | ||
message.reply('Update was done') | ||
|
||
|
||
@respond_to('^smsto (.*)') | ||
@allowed_users(*settings.SUPPORT_USERS) | ||
def sms_to(message, name): | ||
# some code | ||
message.reply('Sms was sent to %s' % name) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Contents | |
plugins | ||
deploy | ||
use_cases | ||
decorators | ||
demo_installation | ||
dev_install | ||
contributing | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
from mattermost_bot.utils import allow_only_direct_message | ||
from mattermost_bot.utils import allowed_users | ||
from mattermost_bot.bot import respond_to | ||
|
||
|
||
@respond_to('^admin$') | ||
@allow_only_direct_message() | ||
@allowed_users('admin', 'root') | ||
def hello_react(message): | ||
def users_access(message): | ||
message.reply('Access allowed!') |