File size: 910 Bytes
16bfc87 |
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 |
from functools import wraps
from typing import Callable
from telegram import Update, ChatAction
from telegram.ext import CallbackContext
from users.models import User
def admin_only(func: Callable):
"""
Admin only decorator
Used for handlers that only admins have access to
"""
@wraps(func)
def wrapper(update: Update, context: CallbackContext, *args, **kwargs):
user = User.get_user(update, context)
if not user.is_admin:
return
return func(update, context, *args, **kwargs)
return wrapper
def send_typing_action(func: Callable):
"""Sends typing action while processing func command."""
@wraps(func)
def command_func(update: Update, context: CallbackContext, *args, **kwargs):
update.effective_chat.send_chat_action(ChatAction.TYPING)
return func(update, context, *args, **kwargs)
return command_func
|