-
Notifications
You must be signed in to change notification settings - Fork 64
/
bot.py
62 lines (58 loc) · 1.99 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import asyncio
import logging
import logging.config
from database import db
from config import Config
from pyrogram import Client, __version__
from pyrogram.raw.all import layer
from pyrogram.enums import ParseMode
from pyrogram.errors import FloodWait
logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.INFO)
logging.getLogger("pyrogram").setLevel(logging.ERROR)
class Bot(Client):
def __init__(self):
super().__init__(
Config.BOT_SESSION,
api_hash=Config.API_HASH,
api_id=Config.API_ID,
plugins={
"root": "plugins"
},
workers=50,
bot_token=Config.BOT_TOKEN
)
self.log = logging
async def start(self):
await super().start()
me = await self.get_me()
logging.info(f"{me.first_name} with for pyrogram v{__version__} (Layer {layer}) started on @{me.username}.")
self.id = me.id
self.username = me.username
self.first_name = me.first_name
self.set_parse_mode(ParseMode.DEFAULT)
text = "**๏[-ิ_•ิ]๏ bot restarted !**"
logging.info(text)
success = failed = 0
users = await db.get_all_frwd()
async for user in users:
chat_id = user['user_id']
try:
await self.send_message(chat_id, text)
success += 1
except FloodWait as e:
await asyncio.sleep(e.value + 1)
await self.send_message(chat_id, text)
success += 1
except Exception:
failed += 1
# await self.send_message("venombotsupport", text)
if (success + failed) != 0:
await db.rmve_frwd(all=True)
logging.info(f"Restart message status"
f"success: {success}"
f"failed: {failed}")
async def stop(self, *args):
msg = f"@{self.username} stopped. Bye."
await super().stop()
logging.info(msg)