-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
405 lines (402 loc) · 19.2 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
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
398
399
400
401
402
403
404
405
import asyncio
import os
import re,json
import discord
from discord.ext import commands, tasks
from discord import app_commands
from discord.utils import get
import random
from datetime import datetime,timedelta
import server
from guild import *
from viettel import *
import vinaphone as vnpt
import vietnamobile
import aiohttp
import ast
import streamlit as st
import ssl
import certifi
import websockets
from websockets.server import serve
intents = discord.Intents.default()
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
VIETTELS='032, 033, 034, 035, 036, 037, 038, 039, 096, 097, 098, 086'
VIETTELS=VIETTELS.split(',')
VINAPHONES=' 091, 094, 088, 081, 082, 083, 084, 085'
VINAPHONES=VINAPHONES.split(',')
VIETNAMOBILE='052, 056, 058, 092'
VIETNAMOBILE=VIETNAMOBILE.split(',')
HEADERS = []
THREADS = []
USERNAMES = []
GUILDID = 1122707918177960047
RESULT=None
#server.b()
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
@client.event
async def on_ready():
global RESULT
#rs=await vietnamobile.login({'phone': '0927847108', 'transId': None, 'user-agent': 'Vietnamobile/4 CFNetwork/1325.0.1 Darwin/21.1.0', 'x-device-id': 'BA7ABF14-BCC4-47EF-964F-DEF1B9E68541', 'token': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMDkyNzQ0OTQxNTM3MDk5Nzc2Iiwicm9sZXMiOltdLCJleHAiOjE3MTExMDg5NjUsImlhdCI6MTcxMTEwMDMyNX0.rNA6wQcSK7RLDIMuJB5xlc0JyCh7TeQ14SeaCXRZg-0LNN89-JY0EK40aptX8qmBWV5RLqbfWL1PanHA1R3Jgg', 'requiredOTP': False, 'refreshToken': '41036610-1df7-4d3b-a1cc-3db9271d31ce'})
#await vietnamobile.getInfo({'phone': '0927847108', 'transId': None, 'user-agent': 'Vietnamobile/4 CFNetwork/1325.0.1 Darwin/21.1.0', 'x-device-id': 'BA7ABF14-BCC4-47EF-964F-DEF1B9E68541', 'token': 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMDkyNzQ0OTQxNTM3MDk5Nzc2Iiwicm9sZXMiOltdLCJleHAiOjE3MTExMDg5NjUsImlhdCI6MTcxMTEwMDMyNX0.rNA6wQcSK7RLDIMuJB5xlc0JyCh7TeQ14SeaCXRZg-0LNN89-JY0EK40aptX8qmBWV5RLqbfWL1PanHA1R3Jgg', 'requiredOTP': False, 'refreshToken': '41036610-1df7-4d3b-a1cc-3db9271d31ce'})
global HEADERS, THREADS, USERNAMES,RESULT
guild = client.get_guild(GUILDID)
RESULT=await getBasic(guild)
if not taskLogin.is_running():
taskLogin.start(guild)
if not taskGetInfo.is_running():
taskGetInfo.start(guild)
if not taskSendOtp.is_running():
taskSendOtp.start(guild)
if not taskUpdatePhone.is_running():
taskUpdatePhone.start(guild)
if not taskKeepCookie.is_running():
taskKeepCookie.start(guild)
@tasks.loop(seconds=1)
async def taskKeepCookie(guild):
global RESULT
RESULT=await getBasic(guild)
@tasks.loop(seconds=1)
async def taskUpdatePhone(guild):
global RESULT
#print('taskUpdatePhone is running')
try:
async for msg in RESULT['rawsCh'].history():
isset=False
for thread in RESULT['phonesCh'].threads:
if msg.content.strip() in thread.name.strip():
isset=True
if not isset:
phone=msg.content.strip()
thread=await RESULT['phonesCh'].create_thread(name=phone,content='loading...')
'''if any(item.strip() in phone for item in VIETTELS):
rs=await sendOtp(phone)
if rs:
await thread.thread.send('New otp sent to '+phone)
elif any(item.strip() in phone for item in VINAPHONES):
rs=await vnpt.sendOtp(phone)
if rs:
await thread.thread.send('New otp sent to '+phone)'''
except Exception as err:
print(err)
pass
@tasks.loop(seconds=3)
async def taskSendOtp(guild):
global RESULT
#print('taskSendOtp is running')
try:
for thread in RESULT['phonesCh'].threads:
if any(item.strip() in thread.name for item in VIETTELS):
msgs=[msg async for msg in thread.history()]
if len(msgs)==1 and 'loading' in msgs[0].content:
rs=await sentOtpReg(thread.name)
if rs:
await thread.send('New otp sent to '+thread.name)
elif any(thread.name.startswith(item.strip()) for item in VIETNAMOBILE):
msgs=[msg async for msg in thread.history()]
if len(msgs)==1 and 'loading' in msgs[0].content:
rs=await vietnamobile.sendOtp(thread.name)
if rs:
await msgs[0].edit(content=rs)
await thread.send('New otp sent to '+thread.name)
except Exception as err:
print(err)
pass
@tasks.loop(seconds=3)
async def taskLogin(guild):
global RESULT
try:
#print('taskLogin is running')
for category in guild.categories:
if 'viettel' in category.name:
for channel in category.channels:
if 'phone' in channel.name:
for thread in channel.threads:
if any(item.strip() in thread.name for item in VIETTELS):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if len(msgs)==3 and 'loading' in msgs[0].content:
otp=msgs[len(msgs)-1].content
rs=await register(thread.name,otp)
if rs:
for i,msg in enumerate(msgs):
if i!=0 and 'headers' not in msgs[0].content:
await msg.delete()
else:
await msg.edit(content=rs)
elif any(item.strip() in thread.name for item in VINAPHONES):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if (len(msgs)==1 and 'loading' in msgs[0].content) or ('session' in msgs[0].content and datetime.datetime.now().timestamp()-msgs[0].edited_at.timestamp()>=3600):
otp=msgs[len(msgs)-1].content
rs=await vnpt.loginByPassword(thread.name)
if rs:
for i,msg in enumerate(msgs):
if i!=0 and 'headers' not in msgs[0].content:
await msg.delete()
else:
await msg.edit(content=rs)
elif any(item.strip() in thread.name for item in VIETNAMOBILE):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if (len(msgs)==3 and 'token' not in msgs[0].content):
otp=msgs[len(msgs)-1].content
headers=ast.literal_eval(msgs[0].content)
rs=await vietnamobile.register(headers,otp)
if rs:
for i,msg in enumerate(msgs):
if i!=0 and 'headers' not in msgs[0].content:
await msg.delete()
else:
await msg.edit(content=rs)
elif ('token' in msgs[0].content and datetime.datetime.now().timestamp()-msgs[0].edited_at.timestamp()>=3600):
headers=ast.literal_eval(msgs[0].content)
rs=await vietnamobile.login(headers)
if rs:
for i,msg in enumerate(msgs):
if i!=0 and 'headers' not in msgs[0].content:
await msg.delete()
else:
await msg.edit(content=rs)
except Exception as err:
print(err)
pass
@tasks.loop(seconds=1)
async def taskGetInfo(guild):
#print('taskGetInfo is running')
try:
RESULT=await getBasic(guild)
for thread in RESULT['phonesCh'].threads:
if any(item.strip() in thread.name for item in VIETTELS):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if len(msgs)==1 and 'loading' not in msgs[0].content or 'headers' in msgs[0].content:
try:
headers=await loginByChecksum(json.loads(msgs[0].content.replace("'",'"')))
rs=await getInfo(headers)
except Exception as err:
print(err)
rs=False
if rs:
js=rs['data']
caution=False
a=False
b=False
embed = discord.Embed(title=js['phone_number']+'- '+js['actStatusName'], description=js['productCode']+'/ '+js['serviceType'],colour=discord.Colour.red()) #,color=Hex code
embed.add_field(name="Owner", value=js['fullName'],inline=True)
embed.add_field(name="CCCD", value=js['cmnd_number'],inline=True)
embed.add_field(name="CCCD_Date", value=js['cmnd_date'],inline=True)
embed.add_field(name="Location", value=js['cmnd_place'],inline=True)
embed.add_field(name="Birthday", value=js['birthday'],inline=True)
embed.add_field(name=" ", value='',inline=False)
for i,item in enumerate(js['extraInfo']):
if i==0 and int(item['value'])<5000:
caution=True
a=True
if item['expire']:
expired=datetime.datetime.strptime(item['expire'],f'%m/%d/%Y %H:%M:%S %p')
expired=expired.strftime('%d/%m/%Y %H:%M:%S %p')
if item['name']=='Tài khoản gốc':
exp=datetime.datetime.strptime(item['expire'],f'%m/%d/%Y %H:%M:%S %p')
if datetime.datetime.now().timestamp()-exp.timestamp()>4320000:
caution=True
b=True
embed.add_field(name=item['name'], value=str(item['value'])+' '+item['unit']+' - expire: '+str(expired),inline=True)
embed.add_field(name=" ", value='',inline=False)
embed.add_field(name="Points", value=js['viettelPlusInfo']['point_can_used'],inline=True)
embed.add_field(name="Point Expire", value=js['viettelPlusInfo']['point_expired'],inline=True)
embed.set_footer(text='Updated at '+str(datetime.datetime.now()+timedelta(hours=7)).split('.')[0]+' ** Powered By VIETTEL')
if len(msgs)==1:
await thread.send(embed=embed)
else:
await msgs[1].edit(embed=embed)
if caution:
ms=''
phone=thread.name
async for msg in RESULT['rawsCh'].history():
if phone.strip()==msg.content.strip():
owner=msg.author
if a or b:
if a:
ms+='**balance too low** '
if b:
ms+='**balance expried soon** '
if caution and len(msgs)==2:
await thread.send(f'⚠️ {owner.mention} {ms} charge money NOW! 🆘')
elif caution and len(msgs)==3:
await msgs[len(msgs)-1].delete()
await thread.send(f'⚠️ {owner.mention} {ms} charge money NOW! 🆘')
elif any(item.strip() in thread.name for item in VINAPHONES):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if len(msgs)==1 and 'loading' not in msgs[0].content or 'session' in msgs[0].content:
#try:
rs=await vnpt.getInfo(json.loads(msgs[0].content.replace("'",'"')))
if rs:
js=rs['data']
caution=False
embed = discord.Embed(title='0'+js['MA_TB'][2:], description=js['LOAI']+'/ '+('Trả sau' if js['TRA_SAU']=="1" else 'Trả trước'),colour=discord.Colour.blue()) #,color=Hex code
embed.add_field(name="Owner", value=js['TEN_TB'],inline=True)
embed.add_field(name="CCCD", value=js['SO_GT'],inline=True)
embed.add_field(name="CCCD_Date", value=js['NGAYCAP_GT'],inline=True)
embed.add_field(name="Location", value=js['DIACHI'],inline=True)
embed.add_field(name="Birthday", value=js['NGAYSINH'],inline=True)
embed.add_field(name=" ", value='',inline=False)
for i,item in enumerate(js['balance']):
if i==2 and item['REMAIN']<5000:
caution=True
embed.add_field(name=item['BALANCE_NAME'], value=str(item['REMAIN'])+' đồng- expire: '+str(item['ACC_EXPIRATION']),inline=True)
embed.add_field(name='Băng thông tốc độ cao', value=js['text_high_bandwidth_volume_remain']+'/ '+js['text_high_bandwidth_volume_total'],inline=True)
embed.add_field(name=" ", value='',inline=False)
embed.add_field(name="Rank", value=js['rank'],inline=True)
embed.add_field(name="Point", value=js['point'],inline=True)
embed.set_footer(text='Updated at '+str(datetime.datetime.now()+timedelta(hours=7)).split('.')[0]+' ** Powered By VINAPHONE')
if len(msgs)==1:
await thread.send(embed=embed)
else:
await msgs[1].edit(embed=embed)
if caution:
phone=thread.name
async for msg in RESULT['rawsCh'].history():
if phone.strip()==msg.content.strip():
owner=msg.author
if caution and len(msgs)==2:
await thread.send(owner.mention)
elif caution and len(msgs)>2:
msgs=[msg async for msg in thread.history(oldest_first=True)]
for i,msg in enumerate(msgs):
if i!=0 and i!=1:
await msg.delete()
await thread.send(owner.mention)
elif any(item.strip() in thread.name for item in VIETNAMOBILE):
msgs=[msg async for msg in thread.history(oldest_first=True)]
if len(msgs)==1 and 'loading' not in msgs[0].content or 'token' in msgs[0].content:
#try:
rs=await vietnamobile.getInfo(ast.literal_eval(msgs[0].content))
if not rs:
headers=await vietnamobile.login(ast.literal_eval(msgs[0].content))
if headers:
await msgs[0].edit(content=headers)
rs=await vietnamobile.getInfo(headers)
if rs:
js=rs
print(js)
caution=False
embed = discord.Embed(title='0'+js['MSISDN'][2:], description=js['CALL_PLAN']+'/ '+('Trả sau' if js['POSTPAID_FLAG']=="Y" else 'Trả trước')+'/ '+('Chặn 1 chiều' if js['LIFECYCLE_STATUS']=='Restricted' else 'Bình thường'),colour=discord.Colour.orange()) #,color=Hex code
embed.add_field(name="Owner", value=js['FULL_NAME'],inline=True)
embed.add_field(name="Gender", value=js['GENDER'],inline=True)
embed.add_field(name="Email", value=js['userInfo']['email'],inline=True)
embed.add_field(name="CCCD", value=js['ID'],inline=True)
embed.add_field(name="CCCD_Date", value=None,inline=True)
embed.add_field(name="Location", value=js['ADDRESS'],inline=True)
embed.add_field(name="Birthday", value=js['DOB'],inline=True)
embed.add_field(name=" ", value='',inline=False)
embed.add_field(name="Tài Khoản Chính", value=js['MAIN_ACCOUNT_BALANCE']+' đồng- expire: '+js['RESTRICTED_DATE'],inline=True)
embed.add_field(name='Băng thông tốc độ cao', value=(js['pcrfServices'][0]['QTALIST'][0]['QTABALANCE']+'/ '+js['pcrfServices'][0]['QTALIST'][0]['QTAVALUE']) if js['pcrfServices'] else None,inline=True)
embed.add_field(name=" ", value='',inline=False)
embed.add_field(name="Rank", value=js['LMS_RANK'],inline=True)
embed.add_field(name="Point", value=js['LMS_POINT'],inline=True)
embed.set_footer(text='Updated at '+str(datetime.datetime.now()+timedelta(hours=7)).split('.')[0]+' ** Powered By VINAPHONE')
if int(js['MAIN_ACCOUNT_BALANCE'])<5000:
caution=True
if len(msgs)==1:
await thread.send(embed=embed)
else:
await msgs[1].edit(embed=embed)
if caution:
phone=thread.name
async for msg in RESULT['rawsCh'].history():
if phone.strip()==msg.content.strip():
owner=msg.author
if caution and len(msgs)==2:
await thread.send(owner.mention)
elif caution and len(msgs)>2:
msgs=[msg async for msg in thread.history(oldest_first=True)]
for i,msg in enumerate(msgs):
if i!=0 and i!=1:
await msg.delete()
await thread.send(owner.mention)
except Exception as err:
print(err)
pass
@tasks.loop(seconds=3)
async def ping():
print(datetime.now())
@tree.command(
name="check_amount_in_phone",
description="check amount avainable in phone",
guild=discord.Object(id=GUILDID)
)
async def first_command(interaction):
await interaction.response.defer()
msgs = [msg async for msg in interaction.channel.history()]
hasText = False
hasImage = False
notEdit = False
for i, msg in enumerate(msgs):
if i == 1 and not msg.author.bot and len(msgs) > 2:
content = msg.content
files = []
temp = []
for att in msg.attachments:
if 'text' in att.content_type:
content = await att.read()
content = content.decode('utf-8')
hasText = True
with open('content.txt', 'w') as file:
file.write(content)
files.append(discord.File('content.txt'))
temp.append('content.txt')
content = ''
elif 'image' in att.content_type:
await att.save(att.filename)
files.append(discord.File(att.filename))
temp.append(att.filename)
hasImage = True
await msg.delete()
elif i == len(msgs)-1:
if 'content' not in locals():
content = ''
if 'files' not in locals():
files = []
if 'temp' not in locals():
temp = []
if len(msgs) == 2 and not msgs[1].author.bot:
notEdit = True
if not hasText and len(content.strip()) == 0:
content = msg.content
for att in msg.attachments:
if 'text' in att.content_type:
content = await att.read()
content = content.decode('utf-8')
with open('content.txt', 'w') as file:
file.write(content)
files.append(discord.File('content.txt'))
temp.append('content.txt')
hasText = True
if not hasImage:
for att in msg.attachments:
if 'image' in att.content_type:
await att.save(att.filename)
files.append(discord.File(att.filename))
temp.append(att.filename)
if notEdit:
name = re.search(
r'.*Tên sản phẩm: (.*?)\..*', content).group(1)
name = name.strip()[0:99]
if hasText:
content = ''
thread = await interaction.channel.parent.create_thread(name=name, content=content, files=files)
await thread.thread.send('Need update!')
await interaction.channel.delete()
else:
if hasText:
content = ''
await msg.edit(content=content, attachments=files)
for file in temp:
if os.path.isfile(file):
os.remove(file)
elif i != 0 and i != len(msgs)-1 and msg.author.bot and not notEdit:
await msg.delete()
if not notEdit:
await interaction.edit_original_response(content='Need update!')
server.b()
client.run(os.environ.get('botToken'))