-
Notifications
You must be signed in to change notification settings - Fork 13
/
bot.py
397 lines (359 loc) · 15.1 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
from telethon.sync import TelegramClient
from telethon import events, Button
from config import Var
import time
import os
import random
from sql_helpers.users_sql import get_user, add_user, remUser, get_all_users, updateLimit, resetDailyLimit, exceededLimitUsers
from sql_helpers.hits_sql import hitExists, addHit, remHit, get_all_hits, get_hit_by_id
import io
import re
from apscheduler.schedulers.asyncio import AsyncIOScheduler
####################################################################
bot = TelegramClient('bot', Var.api_id, Var.api_hash).start(bot_token=Var.token)
####################################################################
joinMsg = """Hello Dear ❤️
[+] For Using This Bot You must Join Channel {channelName}
[+] If u Left The Channel, Bot won't Work 😒
[+] After Joining Channel, Come Back To Bot And Click On /start"""
genMsg = """𝙃𝙚𝙧𝙚 𝙄𝙨 𝙔𝙤𝙪𝙧 {account} 𝘼𝙘𝙘𝙤𝙪𝙣𝙩
𝙀𝙢𝙖𝙞𝙡: `{email}`
𝙋𝙖𝙨𝙨: `{pwd}`
𝙂𝙚𝙣𝙚𝙧𝙖𝙩𝙚𝙙 𝘽𝙮: **{name}**
𝙏𝙝𝙖𝙣𝙠 𝙮𝙤𝙪 𝙛𝙤𝙧 𝙪𝙨𝙞𝙣𝙜 𝙢𝙚!
❤️𝙎𝙝𝙖𝙧𝙚 & 𝙎𝙪𝙥𝙥𝙤𝙧𝙩 **{channelName}**❤️"""
####################################################################
reportMsg = """**New Report**
**Hit Details:-**
ID => `{hitID}`
Email => `{email}`
Password => `{pwd}`
Combo=> `{combo}`
**User Details:-**
ID => `{userID}`
First Name => `{first_name}`
Last Name => `{last_name}`
Username => {username}
Daily Limit => {dailyLimit}/{TotalDailyLimit}
"""
####################################################################
startMsg = """**Hi {name},
I am an Account Generator Bot
-------------------------------------------------
I can provide premium accounts of different services
--------------------------------------------------
Do /gen to generate an account
--------------------------------------------------
❤️Brought to You By @PandaZnetwork || Made by @HeisenbergTheDanger❤️**"""
####################################################################
@bot.on(events.NewMessage(func=lambda e: e.is_private))
async def my_event_handler(event):
try:
if not get_user(event.chat_id) and event.chat_id != Var.channelId:
add_user(event.chat_id)
except:
pass
if Var.channelId:
try:
perm = await bot.get_permissions(Var.channelId, event.chat_id)
except:
await bot.send_message(event.chat_id, joinMsg.format(channelName = Var.channelName))
return
if not (perm.has_default_permissions or perm.is_admin):
await bot.send_message(event.chat_id, joinMsg.format(channelName = Var.channelName))
return
entity = await bot.get_entity(event.chat_id)
first_name = entity.first_name
if "/gen" == event.raw_text.lower():
if Var.maintenanceMode and event.chat_id not in Var.ownerIDs:
await bot.send_message(event.chat_id, "Bot is under maintenance.")
return
user = get_user(event.chat_id)
if not user:
add_user(event.chat_id)
else:
if int(user.dailylimit) >= Var.dailyLimit and event.chat_id not in Var.ownerIDs:
await bot.send_message(event.chat_id, "Daily limit exceeded.")
return
elif int(user.dailylimit) != Var.dailyLimit:
updateLimit(event.chat_id)
accounts = get_all_hits()
if accounts:
hit = random.choice(accounts)
hitID = hit.hitID
hit = hit.hit.split(":")
button = [
[Button.url("Authentication error?", "https://t.me/nordbypass")],
[(Button.inline("Report not working", data=f"report_{hitID}"))]
]
await bot.send_message(event.chat_id, genMsg.format(account = Var.account_name, email = hit[0], pwd = hit[1], name = first_name, channelName = Var.channelName), buttons = button)
else:
await bot.send_message(event.chat_id, "No account available right now.")
if '/start' == event.raw_text.lower():
button = [[(Button.url("Repo Link", "https://github.com/leeveshkamboj/TGAccountGeneratorBot"))]]
await bot.send_message(event.chat_id, startMsg.format(name = first_name), buttons=button)
return
if event.chat_id in Var.ownerIDs:
if '/count' == event.raw_text.lower():
userList = get_all_users()
await bot.send_message(event.chat_id, f"{len(userList)} users.")
if '/hits' == event.raw_text.lower():
hitList = get_all_hits()
if len(hitList) == 0:
msg = "Database is empty."
else:
msg = "**Hits-**\n\n"
for hit in hitList:
msg += (f'{hit.hit}\n')
msg += f'\n**Total {len(hitList)} hits.**'
if len(msg) > 4096:
with io.BytesIO(str.encode(msg)) as out_file:
out_file.name = "hits.txt"
await bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption="List of hits."
)
return
else:
await bot.send_message(event.chat_id, msg)
return
if '/users' == event.raw_text.lower():
userList = get_all_users()
if len(userList) == 0:
msg = "No user found"
else:
msg = "**Users:-**\n\n"
for user in userList:
msg += (f'ID - {user.userId}, Daily limit - {user.dailylimit}/{Var.dailyLimit}\n')
msg += f'\n**Total {len(userList)} user.**'
if len(msg) > 4096:
with io.BytesIO(str.encode(msg)) as out_file:
out_file.name = "users.txt"
await bot.send_file(
event.chat_id,
out_file,
force_document=True,
allow_cache=False,
caption="List of users."
)
return
else:
await bot.send_message(event.chat_id, msg)
return
if '/addhits' == event.raw_text.lower():
if event.is_reply:
try:
previous_message = await event.get_reply_message()
response = previous_message
except:
pass
else:
async with bot.conversation(event.chat_id) as conv:
await conv.send_message('Send hits you want to add.')
try:
response = await conv.get_response()
except:
return
if response.text[0] == "/":
return
hits = response.raw_text.split("\n")
count = 0
for hit in hits:
hit=hit.strip()
hit = hit.split(" ")[0]
if ":" in hit:
if hit[0] == "[":
mail, pwd = hit.split("):", maxsplit = 1)
hit = mail[mail.index("[") + 1 : mail.index("]")] + ":" + pwd
hit = hit.split("|")[0].split(" ")[0]
if not hitExists(hit):
addHit(hit)
count += 1
await bot.send_message(event.chat_id, f"{count} Hit(s) added.")
if '/deletehits' == event.raw_text.lower():
async with bot.conversation(event.chat_id) as conv:
await conv.send_message('Send hits you want to remove.')
try:
response = await conv.get_response()
except:
return
if response.text[0] == "/":
return
hits = response.raw_text.split("\n")
count = 0
for hit in hits:
hit = hit.strip()
hit = hit.split(" ")[0]
if ":" in hit:
if hit[0] == "[":
mail, pwd = hit.split("):", maxsplit = 1)
hit = mail[mail.index("[") + 1 : mail.index("]")] + ":" + pwd
hitID = hitExists(hit).hitID
if hitID:
remHit(hitID)
count += 1
await conv.send_message(f"{count} Hit(s) removed.")
if '/cleanhits' == event.raw_text.lower():
hitList = get_all_hits()
for hit in hitList:
try:
remHit(hit.hitID)
except:
pass
await bot.send_message(event.chat_id, "Cleaned...")
if '/reset' == event.raw_text.lower():
resetMsg = await bot.send_message(event.chat_id, "Resetting...")
await reset(resetMsg)
if '/search' == event.raw_text.lower()[0:7]:
try:
ID = int(event.raw_text.lower()[7:])
except:
await bot.send_message(event.chat_id, "Error")
return
try:
entity = await bot.get_entity(ID)
except:
await bot.send_message(event.chat_id, "Not found")
return
user = get_user(ID)
msg = f"ID = {ID}\n"
msg += f"First name = {entity.first_name}\n"
msg += f"Last name = {entity.last_name}\n"
if entity.username:
msg += f"Username = @{entity.username}\n"
else:
msg += "Username = None\n"
if user:
msg += f"Daily Limit = {user.dailylimit}/{Var.dailyLimit}"
await bot.send_message(event.chat_id, msg)
elif event.raw_text == "/broadcast":
try:
previous_message = await event.get_reply_message()
if previous_message.media:
await bot.send_message(event.chat_id, "Reply to a text msg")
time.sleep(1)
await event.delete()
return
try:
msg = previous_message.text
except:
await bot.send_message(event.chat_id, event.message.id, "Reply to a text msg")
time.sleep(1)
await event.delete()
return
userList = get_all_users()
if len(userList) == 0:
msg = "No user found"
else:
bMsg = await bot.send_message(event.chat_id, f"Sending to {len(userList)} users.")
err = 0
succ = 0
count = 0
errs = ""
for user in userList:
try:
await bot.send_message(int(user.userId), msg)
succ += 1
except Exception as e:
err += 1
errs += f"Userid - {user.userId} Error - {e}\n"
count += 1
percents = round(100.0 * count / float(len(userList)), 1)
try:
await bot.edit_message(event.chat_id, bMsg.id, f"Sending... [{percents}%]\n{err} error(s) till now.")
except:
pass
await bot.edit_message(event.chat_id, bMsg.id, f"Successfully sent to {succ} users with {err} errors.")
except Exception as error:
await bot.send_message(event.chat_id, "Reply to a text msg")
if 'yo' == event.raw_text.lower():
await event.reply('yo')
return
async def reset(resetMsg = None):
msg = "Limit Has Been Reset , You can Generate Your Accounts Now !"
users = exceededLimitUsers(Var.dailyLimit)
count = 0
for user in users:
try:
await bot.send_message(int(user.userId), msg)
except Exception as e:
pass
count += 1
if resetMsg:
percents = round(100.0 * count / float(len(users)), 1)
try:
await bot.edit_message(resetMsg.chat_id, resetMsg.id, f"Sending... [{percents}%]")
except:
pass
resetDailyLimit()
if resetMsg:
await bot.edit_message(resetMsg.chat_id, resetMsg.id, "Done")
@bot.on(events.callbackquery.CallbackQuery(data=re.compile(b"report_(.*)")))
async def genAcc(event):
hitID = event.data_match.group(1).decode("UTF-8")
try:
hit = get_hit_by_id(hitID)
email, pwd = hit.hit.split(":", maxsplit = 1)
entity = await bot.get_entity(event.chat_id)
username = entity.username
user = get_user(event.chat_id)
if username:
username = "@" + username
msg = reportMsg.format(
hitID = hitID,
email = email,
pwd = pwd,
combo = hit.hit,
userID = event.chat_id,
first_name = entity.first_name,
last_name = entity.last_name,
username = username,
dailyLimit = user.dailylimit,
TotalDailyLimit = Var.dailyLimit
)
button = [
[(Button.inline("Remove Now", data=f"remove_{hitID}"))],
[(Button.inline("Ignore", data="ignore"))]
]
if Var.reportGroupId:
await bot.send_message(Var.reportGroupId, msg, buttons=button)
else:
await bot.send_message(Var.ownerIDs[0], msg, buttons=button)
except:
pass
await event.answer("Report Sent to Admins!", alert=True)
newButton = [Button.url("Authentication error?", "https://bit.ly/35gd38D")]
await bot.edit_message(event.chat_id, event.query.msg_id, buttons = newButton)
@bot.on(events.callbackquery.CallbackQuery(data=re.compile(b"remove_(.*)")))
async def genAcc(event):
if event.query.user_id not in Var.ownerIDs:
await event.answer("Access Denied")
return
hitID = event.data_match.group(1).decode("UTF-8")
try:
if get_hit_by_id(hitID):
remHit(hitID)
await event.answer("Removed.", alert=True)
await event.delete()
else:
await event.answer("Hits already removed.", alert=True)
await event.delete()
except Exception as e:
if Var.reportGroupId:
await bot.send_message(Var.reportGroupId, f"Error - {e}")
else:
await bot.send_message(Var.ownerIDs[0], f"Error - {e}")
@bot.on(events.callbackquery.CallbackQuery(data=re.compile(b"ignore")))
async def genAcc(event):
if event.query.user_id not in Var.ownerIDs:
await event.answer("Access Denied")
return
await event.delete()
scheduler = AsyncIOScheduler(timezone="Asia/Kolkata")
scheduler.add_job(reset, 'cron', hour=0)
scheduler.start()
print("Bot Started.")
bot.run_until_disconnected()