Skip to content

Commit

Permalink
feat: implement admin method decorator
Browse files Browse the repository at this point in the history
The @admin_method decorator limits who can execute certain methods
  • Loading branch information
d-Rickyy-b committed Aug 16, 2020
1 parent 6e935e7 commit 5473e23
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions blackjackbot/bot/commands/admin/commands.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
# -*- coding: utf-8 -*-
import logging

from blackjackbot.lang import translate
from database import Database


def admin_method(func):
"""Decorator for marking methods as admin-only methods, so that strangers can't use them"""

def admin_check(update, context):
user = update.message.from_user
if user.id in Database().get_admins():
return func(update, context)
else:
update.message.reply_text(translate("no_permission"))
logging.warning("User {} ({}, @{}) tried to use admin function '{}'!".format(user.id, user.first_name, user.username, func.__name__))

return admin_check


def notify_admins(text, context):
"""
Sends a message to all stored admins
Expand All @@ -16,3 +33,8 @@ def notify_admins(text, context):

def reload_languages_cmd(update, context):
pass


@admin_method
def answer_comment_cmd(upate, context):
pass

0 comments on commit 5473e23

Please sign in to comment.