-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.py
More file actions
30 lines (26 loc) · 836 Bytes
/
ext.py
File metadata and controls
30 lines (26 loc) · 836 Bytes
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
#!/usr/bin/env python
# pylint: disable=C0116,W0613
import asyncio
from .bot import PBot
from telegram import Update
from telegram.ext import (
CallbackContext,
CommandHandler
)
def aexec(func):
def wrapper(update: Update, context: CallbackContext):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(func(update, context))
loop.close()
return wrapper
def async_command(**kwargs):
def wrapper(func):
updater = PBot.updater
updater.dispatcher.add_handler(CommandHandler(kwargs["name"], func, run_async=True))
return wrapper
def command(**kwargs):
def wrapper(func):
updater = PBot.updater
updater.dispatcher.add_handler(CommandHandler(kwargs["name"], func))
return wrapper