-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.py
76 lines (69 loc) · 2.31 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from fastapi import FastAPI, Request, Response
from fastapi.responses import HTMLResponse, FileResponse
import requests
import json
import random
from pyrogram import *
import secrets
from dateutil import parser
import requests
import os
from pymongo import MongoClient
MONGO_URL = "mongo db url" # https://www.mongodb.com/
API_ID = "1267i" # telegram api I'd my.telegram.org
API_HASH = "jsksko12i0" # telegram api hash my.telegram.org
TOKEN = "bot token" # telegram bot token
hosturl = "site url"
CHAT_ID = -1001787468565 # telegram channel id
async def clientbot():
bot = Client(
':memory:',
api_id=API_ID,
api_hash=API_HASH,
bot_token=TOKEN
)
await bot.start()
return bot
app = FastAPI()
@app.get('/api/apikey={api}/{botname}/{owner}/message={msg}')
async def chatbot(api, botname, owner, msg):
leveldb = MongoClient(MONGO_URL)
toggle = leveldb["myFirstDatabase"]["jsons"]
is_token = toggle.find_one({"ID": api})
result = f"https://{hosturl}/chatbot/{botname}/{owner}/message={msg}"
result = requests.get(result)
result = result.json()
if not is_token:
url = f"https://{hosturl}/api/apikey={api}/{botname}/{owner}/message={msg}"
bot = await clientbot()
await bot.send_message(CHAT_ID, f"Invalid Token\n - {url}")
ret = {
"reply": "Invalid Token Please Ask @metavoidsupport"
}
return ret
if is_token:
ret = {
"reply": result["reply"]
}
return ret
@app.get('/api/apikey={api}/message={msg}')
async def simplechatbot(api, msg):
leveldb = MongoClient(MONGO_URL)
toggle = leveldb["myFirstDatabase"]["jsons"]
is_token = toggle.find_one({"ID": api})
result = f"https://{hosturl}/chatbot/kuki/moezilla/message={msg}"
result = requests.get(result)
result = result.json()
if not is_token:
url = f"https://{hosturl}/api/apikey={api}/message={msg}"
bot = await clientbot()
await bot.send_message(CHAT_ID, f"Invalid Token\n - {url}")
ret = {
"reply": "Invalid Token Please Ask @metavoidsupport"
}
return ret
if is_token:
ret = {
"reply": result["reply"]
}
return ret