-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (40 loc) · 1.36 KB
/
main.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
import asyncio
import logging
import event_handlers
import command_handlers
from on_start import apps
from logger.logger import log, LogMode
from pyrogram.methods.utilities.idle import idle
from pyrogram.dispatcher import Dispatcher
from patch_dispatcher import PatchedDispatcher
Dispatcher.handler_worker = PatchedDispatcher.handler_worker
async def start_bot():
for a in apps:
await a.start()
log("----------USERBOT STARTED----------", LogMode.OK)
command_handlers.initialize_commands()
event_handlers.initialize_filters()
log("----------MODULES INITIALIZED----------", LogMode.OK)
async def stop_bot():
for a in apps:
await a.stop(block=True)
log("----------USERBOT STOPED CORRECTLY----------", LogMode.OK)
async def main():
try:
await start_bot()
logging.getLogger().setLevel(100)
await idle()
await stop_bot()
except KeyboardInterrupt:
log("----------USERBOT STOPED MANUALLY LOCAL----------", LogMode.OK)
else:
log("----------USERBOT STOPED----------", LogMode.OK)
finally:
log("----------USERBOT CLOSED----------", LogMode.OK)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
run = loop.run_until_complete
try:
run(main())
except KeyboardInterrupt:
log("----------USERBOT STOPED MANUALLY GLOBAL----------", LogMode.OK)