-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
60 lines (44 loc) · 1.23 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
55
56
57
58
59
60
import asyncio
import logging
from pyrogram import Client
from config import API_HASH, API_ID, BOT_TOKEN, REPLIT
from plugins.ticker import BTCTicker
from utils import ping_server
logging.getLogger().setLevel(logging.INFO)
if REPLIT:
from threading import Thread
from flask import Flask, jsonify
app = Flask('')
@app.route('/')
def main():
res = {
"status":"running",
"hosted":"replit.com",
}
return jsonify(res)
def run():
app.run(host="0.0.0.0", port=8000)
async def keep_alive():
server = Thread(target=run)
server.start()
class Bot(Client):
def __init__(self):
super().__init__(
"BTCTicker",
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
plugins=dict(root="plugins")
)
async def start(self):
if REPLIT:
await keep_alive()
asyncio.create_task(ping_server())
await super().start()
await asyncio.create_task(BTCTicker(self))
logging.info('Task Created')
logging.info('Bot started')
async def stop(self, *args):
await super().stop()
logging.info('Bot Stopped Bye')
Bot().run()