Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
42 lines (34 loc) · 1.31 KB
/
Copy pathapp.py
File metadata and controls
42 lines (34 loc) · 1.31 KB
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
38
39
40
41
42
import asyncio
import logging
from pyrogram import Client
from pyrogram.types import BotCommand
from data.config import *
app = Client(
"MY_CLIENT",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN if BOT_TOKEN is not None else None,
plugins=dict(root="handlers")
)
logging.basicConfig(level=logging.INFO)
async def main():
"""
`main` is an async function that runs before the bot
"""
# if you are running this bot first time set generate=True, it creates database, later set it to False
await init_db(generate=True)
async with app:
if app.bot_token is not None:
# register commands
await app.set_bot_commands(commands=[BotCommand(command="start", description="Start the bot"),
BotCommand(command="help", description="Get help from the bot"),
BotCommand(command="kb", description="get sample inline keyboard"), ])
await app.send_message(admins[0], "Bot started")
if __name__ == "__main__":
try:
asyncio.get_event_loop().run_until_complete(main())
logging.info("Bot started")
app.run()
except KeyboardInterrupt:
logging.info("Bot stopped")
asyncio.get_event_loop().run_until_complete(close_db())