-
Notifications
You must be signed in to change notification settings - Fork 360
/
bot.py
32 lines (27 loc) · 951 Bytes
/
bot.py
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
import env
import logging
from pyrogram import Client, idle
from pyromod import listen # type: ignore
from pyrogram.errors import ApiIdInvalid, ApiIdPublishedFlood, AccessTokenInvalid
logging.basicConfig(level=logging.INFO, encoding="utf-8", format="%(asctime)s - %(levelname)s - \033[32m%(pathname)s: \033[31m\033[1m%(message)s \033[0m")
app = Client(
"Session_bot",
api_id=env.API_ID,
api_hash=env.API_HASH,
bot_token=env.BOT_TOKEN,
in_memory=True,
plugins={'root':'StringSessionBot'},
)
if __name__ == "__main__":
logging.info("Starting the bot")
try:
app.start()
except (ApiIdInvalid, ApiIdPublishedFlood):
raise Exception("Your API_ID/API_HASH is not valid.")
except AccessTokenInvalid:
raise Exception("Your BOT_TOKEN is not valid.")
uname = app.me.username
logging.info(f"@{uname} is now running!")
idle()
app.stop()
logging.info("Bot stopped. Alvida!")