forked from Shubhamdev89/BroadcastBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
47 lines (40 loc) · 1.29 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
import os
from pyrogram import Client
import config
from handlers.database import Database
from aiohttp import web
from datetime import datetime
routes = web.RouteTableDef()
BOT_USERNAME = ''
@routes.get("/", allow_head=True)
async def root_route_handler(request):
return web.json_response(F"Bot @{BOT_USERNAME} is successfully running...")
async def web_server():
web_app = web.Application(client_max_size=30000000)
web_app.add_routes(routes)
return web_app
class Bot(Client):
def __init__(self):
super().__init__(
"BroadcastBot",
bot_token=config.BOT_TOKEN,
api_id=config.API_ID,
api_hash=config.API_HASH,
plugins={
"root": "plugins"
},
)
async def start(self):
global BOT_USERNAME
await super().start()
usr_bot_me = await self.get_me()
self.uptime = datetime.now()
BOT_USERNAME = usr_bot_me.username
print(f"@{usr_bot_me.username} Bot Running..!")
app = web.AppRunner(await web_server())
await app.setup()
bind_address = "0.0.0.0"
await web.TCPSite(app, bind_address, os.environ.get("PORT", "8080")).start()
async def stop(self, *args):
await super().stop()
print("Bot stopped.")