-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·246 lines (200 loc) · 9.72 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import telebot
from flask import Flask,request
from telebot import util
import time
from telebot import types as tp
from pymongo import MongoClient
import os
import json
from ChannelData import runner
from DataOrg import JsonPacker
token = 'token'
ADMIN_CHAT = 'Admin Chat ID'
welcome = ''
about = ''
help_ = ''
url = 'WebHook Url'
bot = telebot.TeleBot(token)
client = MongoClient(os.getenv('MONGODB_URI'))
db = client.AnimeFlix_Database
collections = db.UserID
server = Flask(__name__)
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['start'])
def start_(message):
try:
bot.send_message(message.chat.id,welcome,parse_mode='markdown')
except Exception:pass
username = '@'+message.from_user.username.replace('_','\_') if message.from_user.username != None else ""
info = f'*Name* - {message.from_user.first_name} {message.from_user.last_name if message.from_user.last_name!=None else ""}\n*Username* - {username}\n*ID* - `{message.from_user.id}`'
try:
bot.send_message(ADMIN_CHAT,info,parse_mode='markdown')
except Exception:pass
db_info = {'_id':message.from_user.id,'name':f'{message.from_user.first_name} {message.from_user.last_name if message.from_user.last_name!=None else ""}','username':message.from_user.username}
try: collections.insert_one(db_info)
except Exception as e: print(e)
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['about'])
def about_(message):
main = tp.InlineKeyboardMarkup(row_width=2)
slot1 = tp.InlineKeyboardButton('Slot 1',url='')
slot2 = tp.InlineKeyboardButton('Slot 2',url='')
slot3 = tp.InlineKeyboardButton('Slot 3',url='')
main.add(slot3,slot1,slot2)
try:
bot.send_message(message.chat.id,about,parse_mode='markdown',reply_markup=main)
except Exception:pass
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['help'])
def help_(message):
main = tp.InlineKeyboardMarkup(row_width=2)
slot1 = tp.InlineKeyboardButton('Slot 1',url='')
slot2 = tp.InlineKeyboardButton('Slot 2',url='')
slot3 = tp.InlineKeyboardButton('Slot 3',url='')
main.add(slot3,slot1,slot2)
try:
bot.send_message(message.chat.id,help_,parse_mode='markdown',reply_markup=main)
except Exception:pass
#*--------------------------------------------------------------------------------------------------------------------------------------
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['update'])
def update_(msg):
if msg.chat.id == ADMIN_CHAT:
bot.send_message(msg.chat.id,'Getting Data From Channel...')
try:
runner()
except:
bot.send_message(msg.chat.id,'Failed To Fetch!')
time.sleep(3)
bot.send_message(msg.chat.id,'Packing Data in JSON...')
try:
JsonPacker()
except:
bot.send_message(msg.chat.id,'Failed To Pack!')
finally:
bot.send_message(msg.chat.id,'Done!!')
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['broadcast'])
def broadcast(message):
if message.chat.id == ADMIN_CHAT:
if not message.reply_to_message: bot.send_message(message.chat.id,'Please reply to a text message to send.')
if message.reply_to_message:
IDs = collections.distinct('_id')
sleep_var = 26
for id_ in IDs:
if sleep_var%25 == 0:
time.sleep(0.6)
sleep_var += 1
else:
try:
bot.send_message(id_,message.reply_to_message.text)
sleep_var += 1
except Exception as e:
print(e)
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['block'])
def block(msg):
if msg.chat.id == ADMIN_CHAT:
if msg.reply_to_message:
try:
bot.send_message(msg.reply_to_message.forward_from.id,'Please Stop Spamming.\nYour requests has been paused for 10 minutes.')
except: pass
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(commands=['send'])
def send(message):
if message.chat.id == ADMIN_CHAT:
ID = util.extract_arguments(message.text)
if message.reply_to_message:
try:
bot.send_message(ID,message.reply_to_message.text)
except Exception: bot.send_message(ADMIN_CHAT,'Somethign went wrong...Try Again.')
elif not message.reply_to_message: bot.send_message(ADMIN_CHAT,'Please reply to a text message to send.')
#*--------------------------------------------------------------------------------------------------------------------------------------
@bot.message_handler(content_types=['text','sticker','photo','video','audio','document'])
def user_to_admin(message):
if message.chat.id == ADMIN_CHAT:
if message.reply_to_message:
try:
m = message.reply_to_message.forward_from.id
except Exception: pass
try: bot.send_message(m,message.text)
except Exception: pass
try: bot.send_sticker(m,message.sticker.file_id)
except Exception: pass
try: bot.send_photo(m,message.photo.file_id)
except Exception: pass
try: bot.send_video(m,message.video.file_id)
except Exception: pass
try: bot.send_audio(m,message.audio.file_id)
except Exception: pass
else: pass
else:
try : bot.forward_message(ADMIN_CHAT,message.chat.id,message.message_id)
except Exception: pass
#*--------------------------------------------------------------------------------------------------------------------------------------
if message.content_type=='text' and message.chat.id != ADMIN_CHAT:
with open('urls.json','r') as f:
data = json.load(f)
text = message.text
def WordFinder(queryWord):
ignorelist = ['a','an','k','want','your','the','and','on','to','in','are','for','by','you','me','yes','no','of','is','it','I','.','/',',','[',']','?',':',';','-','(',')','!']
point = []
sentences = data.keys()
for sentence in sentences:
wordPoint = 0
sentence_ = None
queryWord = queryWord.lower()
sentence2 = sentence.lower()
if sentence2[1:] in queryWord and len(sentence2[1:]) > 3:
if not sentence[1:] in ['h','k','b']:
wordPoint += 1
sentence_ = sentence
if queryWord in sentence2.replace('!','') and len(queryWord) > 3:
if not queryWord in ignorelist:
wordPoint += 1
sentence_ = sentence
for word in sentence2.split(' '):
if ' ' in queryWord:
words = queryWord.split(' ')
for word_ in words:
if not word_ in ignorelist:
if word_ == word:
wordPoint += 1
sentence_ = sentence
elif word == queryWord:
if not word in ignorelist:
wordPoint += 1
sentence_ = sentence
if sentence_ != None:
point.append({wordPoint:sentence_})
return point
result = WordFinder(text)
Num = []
wordcount = 1 if len(text.split(' ')) <= 1 else 2
for dict_ in result:
for k,v in dict_.items():
Num.append(k)
buttons = []
for dict_ in result:
buttons.append([tp.InlineKeyboardButton(text=name[1:],url=data[name]) for num,name in dict_.items() if num >= wordcount])
main = tp.InlineKeyboardMarkup(row_width=1)
for button in buttons:
for b in button:
main.add(b)
for button in buttons:
if button:
sent = bot.send_message(message.chat.id,'*Are you looking for this?*',reply_markup=main,parse_mode='markdown')
bot.forward_message(ADMIN_CHAT,message.chat.id,sent.message_id)
break
#*--------------------------------------------------------------------------------------------------------------------------------------
@server.route('/' + token, methods=['POST'])
def getMessage():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
return "!", 200
@server.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(url=url + token)
return "!", 200
if __name__ == "__main__":
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))