-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathbot.py
More file actions
66 lines (57 loc) · 2.08 KB
/
bot.py
File metadata and controls
66 lines (57 loc) · 2.08 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
import os
from datetime import datetime
from pytz import timezone
from pyrogram import Client
from aiohttp import web
from config import API_ID, API_HASH, BOT_TOKEN, ADMIN, LOG_CHANNEL
routes = web.RouteTableDef()
@routes.get("/", allow_head=True)
async def root_route(request):
return web.Response(text="<h3 align='center'><b>I am Alive</b></h3>", content_type='text/html')
async def web_server():
app = web.Application(client_max_size=30_000_000)
app.add_routes(routes)
return app
class Bot(Client):
def __init__(self):
super().__init__(
"techifybots",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
plugins=dict(root="TechifyBots"),
workers=200,
sleep_threshold=15
)
async def start(self):
app = web.AppRunner(await web_server())
await app.setup()
try:
await web.TCPSite(app, "0.0.0.0", int(os.getenv("PORT", 8080))).start()
print("Web server started.")
except Exception as e:
print(f"Web server error: {e}")
await super().start()
me = await self.get_me()
print(f"Bot Started as {me.first_name}")
if isinstance(ADMIN, int):
try:
await self.send_message(ADMIN, f"**{me.first_name} is started...**")
except Exception as e:
print(f"Error sending message to admin: {e}")
if LOG_CHANNEL:
try:
now = datetime.now(timezone("Asia/Kolkata"))
msg = (
f"**{me.mention} is restarted!**\n\n"
f"📅 Date : `{now.strftime('%d %B, %Y')}`\n"
f"⏰ Time : `{now.strftime('%I:%M:%S %p')}`\n"
f"🌐 Timezone : `Asia/Kolkata`"
)
await self.send_message(LOG_CHANNEL, msg)
except Exception as e:
print(f"Error sending to LOG_CHANNEL: {e}")
async def stop(self, *args):
await super().stop()
print(f"{me.first_name} Bot stopped.")
Bot().run()