-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
132 lines (71 loc) · 2.15 KB
/
__main__.py
File metadata and controls
132 lines (71 loc) · 2.15 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import glob
import logging
import asyncio
from pathlib import Path
from telethon import TelegramClient
import os, sys
from telegram_bot.utils import load_plug
from telegram_bot import bot, bot_token
# Set up logging
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.WARNING)
# Load all plugins
plugin_path = "telegram_bot/plugins/*.py"
files = glob.glob(plugin_path)
for name in files:
with open(name) as f:
pxt = Path(f.name)
plug = pxt.stem
load_plug(plug.replace(".py", ""))
print("ALL PLUGINS Loaded !!")
# Start the bot
async def main():
await bot.start(bot_token=bot_token)
print("Bot started successfully!")
from sys import argv
if len(argv) not in (1, 3, 4):
await bot.disconnect()
else:
await bot.run_until_disconnected()
if __name__ == "__main__":
try:
asyncio.run(main())
except Exception as e:
print(f" Error: {e}")
finally:
print("Bot shutting down cleanly.")
"""import glob
from pathlib import Path
from amit.utils import load_plug
from amit import bot, bot_token
import logging
from sys import argv
import asyncio
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.WARNING)
path = "amit/plugins/*.py"
files = glob.glob(path)
for name in files:
with open(name) as a:
pxt = Path(a.name)
plugs = pxt.stem
load_plug(plugs.replace(".py", ""))
print ("AMIT BOT HAS STARTED & LOADED ALL PLUGINS ")
async def main():
# Close the session and reopen it
bot.session.close()
bot.session = None # Set session to None so it will reopen a new one
# Start the bot asynchronously
await bot.start(bot_token=bot_token)
# This will now print after the bot has started
print("Bot started successfully!")
if len(argv) not in (1, 3, 4):
bot.disconnect()
else:
# Keep the bot running until disconnected
await bot.run_until_disconnected()
if __name__ == "__main__":
try:
# await bot.run_until_disconnected()
asyncio.run(main())
finally:
print("Bot shutting down cleanly.")
"""