Skip to content

Instantly share code, notes, and snippets.

@saschalalala
Created June 3, 2017 15:24
Show Gist options
  • Save saschalalala/c19627de9d6a0f2f9eed2b4e1ee44654 to your computer and use it in GitHub Desktop.
Save saschalalala/c19627de9d6a0f2f9eed2b4e1ee44654 to your computer and use it in GitHub Desktop.
telegram_bot decorators
def admin_only(func):
def check_permissions(*args, **kwargs):
bot = args[0]
update = args[1]
admin_ids = list(Player.objects.filter(gm=True).values_list('telegram_id', flat=True))
current_user = update.message.from_user
if current_user.id not in admin_ids:
update.message.reply_text("You are not allowed to do this, Troubleshooter. This incident will be reported")
message = "The user {} just entered a forbidden command.".format(current_user)
log_channel_id = Game.objects.get(pk=1).channel_id
bot.sendMessage(log_channel_id, message)
return 1
return func(*args, **kwargs)
return check_permissions
def silent_in_group(func):
def dont_process_commands_from_groups(*args, **kwargs):
bot = args[0]
update = args[1]
if update.message.chat.id < 0:
current_user = update.message.from_user
bot.send_message(current_user.id, 'Commands from group chats are not supported, please repeat')
return 1
return func(*args, **kwargs)
return dont_process_commands_from_groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment