-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbot.py
More file actions
479 lines (449 loc) · 23.7 KB
/
Copy pathbot.py
File metadata and controls
479 lines (449 loc) · 23.7 KB
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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
import discord
import os
import codecs
from discord.embeds import Embed
from discord.ext.commands.core import command
from dotenv import load_dotenv
from discord.ext import commands
from discord.ext import tasks
from embedReplies import *
import getSkinOffers
import getHeader
import db
import getBalance
load_dotenv()
TOKEN = os.getenv('TOKEN')
# TOKEN = os.getenv('DEV_TOKEN')
# TOKEN = os.getenv('DEV_TOKEN3')
bot = commands.AutoShardedBot(shard_count=5, command_prefix="+")
bot.remove_command('help')
@bot.event
async def on_ready():
# if not sendReminder.is_running():
# sendReminder.start()
if not switch_presense.is_running():
switch_presense.start()
print(f"We have logged in as {bot.user}")
@bot.event
async def on_guild_join(guilds):
count = len(bot.guilds)
db.updateServerCount(count)
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
embed=smallEmbed("Command not found!","Please use +help to use the available commands!")
try:
await ctx.send(embed=embed)
except Exception as e:
print(e)
@tasks.loop(hours=2)
async def switch_presense():
serverCount = db.getServerCount()
await bot.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name=f"+help in {serverCount['server_count']} servers"))
@tasks.loop(hours=24)
async def sendReminder():
reminders = db.getReminders()
# reminders = db.getDevReminders() #DEV
for reminder in reminders:
if(db.checkUser(reminder['username'],reminder['region'])):
user = await bot.fetch_user(int(reminder['discord_id']))
user_db=db.getUser(reminder['username'],reminder['region'])
password=user_db['password']
try:
headers,user_id = await getHeader.run(reminder['username'],password,reminder['region'])
if headers==403:
embed = smallEmbed("Update Password!","+updatepass <username> <updated password> <region>")
# await user.send(embed=embed)
continue
else:
res = await getSkinOffers.getStore(headers,user_id,reminder['region'])
for item in res[0]:
if(item[0].lower()==reminder['weapon'].lower()):
embed = discord.Embed(title="Reminder", description=f"This is to inform you that, {reminder['weapon'].title()} is now in your store! 🥳", color=discord.Color.red())
embed.set_image(url=item[2])
embed.set_thumbnail(url='https://emoji.gg/assets/emoji/confetti.gif')
try:
await user.send(embed=embed)
print(f'{user.id} , {user.display_name} has gotten reminder')
except Exception as e:
print("Exception while sending user embed \n")
print(e)
# logger.error(e)
continue
except Exception as e:
print("Exception after headers \n")
print(e)
print("\n")
continue
else:
try:
embed=smallEmbed("Add user","+adduser <username> <password> <region>")
# await user.send(embed=embed)
embed=smallEmbed("Add user","Please add your user in private message!")
# await user.send(embed=embed)
except Exception as e:
print("Exception after everything \n")
print(e)
print("\n")
continue
@bot.command(name="store")
async def store(ctx,*,args=None):
if args!=None and len(args.split())==2:
username,region=args.split()
if region not in ['ap','eu','kr','na']:
embed = incorrectRegion()
await ctx.channel.send(embed=embed)
return
if(db.checkUser(username,region)):
user=db.getUser(username,region)
password=user['password']
try:
headers,user_id = await getHeader.run(username,password,region)
if headers==403:
embed = smallEmbed("Update Password!","+updatepass <username> <updated password> <region>")
await ctx.channel.send(embed=embed)
return
elif headers==429:
embed = smallEmbed("Rate Limited!",f'{username} has been rate limited by Riot.\nPlease try again after 10 minutes')
await ctx.channel.send(embed=embed)
return
elif headers==405:
embed = smallEmbed("2FA Detected!",f'{username} has enabled 2FA.\nPlease try again after switching off 2FA')
await ctx.channel.send(embed=embed)
return
else:
res = await getSkinOffers.getStore(headers,user_id,region)
for item in res[0]:
embed = discord.Embed(title=item[0], description=f"Valorant Points:{item[1]}", color=discord.Color.red())
embed.set_thumbnail(url=item[2])
await ctx.channel.send(embed=embed)
embed=smallEmbed("Offer ends in",res[1])
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=smallEmbed("Add user!","+adduser <username> <password> <region>")
await ctx.author.send(embed=embed)
if not isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
embed=smallEmbed("Add user","Please add your user in private message!")
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+store <username> <region>")
await ctx.channel.send(embed=embed)
@bot.command(name="adduser")
async def adduser(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
if args!=None and len(args.split())==3:
username,password,region = args.split()
if region not in ['ap','eu','kr','na']:
embed=incorrectRegion()
await ctx.channel.send(embed=embed)
return
else:
try:
if(db.checkUser(username,region)):
embed=smallEmbed("User already exists","Please check +help for available commands")
await ctx.channel.send(embed=embed)
else:
_,res = await getHeader.run(username,password,region)
if(res==403):
embed=smallEmbed("Incorrect credentials!","Your login credentials don't match an account in our system")
await ctx.channel.send(embed=embed)
return
else:
res=db.addUserDb(username,password,region)
if res:
embed=thumbnailEmbed("User Added!","User has been successfully added","https://emoji.gg/assets/emoji/confetti.gif")
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+adduser <username> <password> <region>")
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
embed=smallEmbed("Add user!","+adduser <username> <password> <region>")
await ctx.author.send(embed=embed)
@bot.command(name="deluser")
async def deluser(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
if args!=None and len(args.split())==3:
username,password,region = args.split()
if region not in ['ap','eu','kr','na']:
embed=incorrectRegion()
await ctx.channel.send(embed=embed)
return
else:
try:
if not (db.checkUser(username,region)):
embed=smallEmbed("User does not exist in our system","Add your account using +adduser")
await ctx.channel.send(embed=embed)
else:
_,res = await getHeader.run(username,password,region)
if(res==403):
embed=smallEmbed("Incorrect credentials!","Your login credentials don't match an account in our system")
await ctx.channel.send(embed=embed)
return
else:
res=db.delUser(username,region)
if res:
embed=thumbnailEmbed("User Deleted!","User has been successfully deleted!","https://emoji.gg/assets/emoji/confetti.gif")
await ctx.channel.send(embed=embed)
else:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+deluser <username> <password> <region>")
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("Delete user!","+deluser <username> <password> <region>")
await ctx.author.send(embed=embed)
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
@bot.command(name="bal")
async def bal(ctx,*,args=None):
if args!=None and len(args.split())==2:
username,region=args.split()
if region not in ['ap','eu','kr','na']:
embed=incorrectRegion()
await ctx.channel.send(embed=embed)
return
if(db.checkUser(username,region)):
user=db.getUser(username,region)
password=user['password']
try:
headers,user_id = await getHeader.run(username,password,region)
val_points,rad_points=await getBalance.viewBal(headers,user_id,region)
embed = discord.Embed(title="Balance", description=f"Valorant Points:{val_points} \nRadianite Points:{rad_points}", color=discord.Color.red())
embed.set_thumbnail(url="https://media.valorant-api.com/currencies/e59aa87c-4cbf-517a-5983-6e81511be9b7/displayicon.png")
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=smallEmbed("Add user!","+adduser <username> <password> <region>")
await ctx.author.send(embed=embed)
if not isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
embed=smallEmbed("Add user","Please add your user in private message!")
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+bal <username> <region>")
await ctx.channel.send(embed=embed)
@bot.command(name="help")
async def help_(context):
helpEmbed = discord.Embed(title="Help",description="Summary of all available commands",color=discord.Color.red())
helpEmbed.set_thumbnail(url="https://i.imgur.com/jnqBJFs.png")
helpEmbed.add_field(name="+adduser",value="Adds your user", inline=False)
helpEmbed.add_field(name="+store", value="Shows all the available weapon skins in your store", inline=False)
helpEmbed.add_field(name="+bal",value="Shows the balance of your account", inline=False)
helpEmbed.add_field(name="+reminder",value="Sets reminder of your favourite skin and notifies you if it is available in your store", inline=False)
helpEmbed.add_field(name="+showreminder",value="Shows all the reminder that is set by user", inline=False)
helpEmbed.add_field(name="+delreminder",value="Deletes the reminder that is set", inline=False)
helpEmbed.add_field(name="+skins",value="Links to weapon skins available in-game", inline=False)
helpEmbed.add_field(name="+updatepass",value="Updates the password", inline=False)
helpEmbed.add_field(name="+deluser",value="Deletes the user from database", inline=False)
helpEmbed.add_field(name="\u200B",value="Join our support server [here](https://discord.gg/zHTGSaAjp8)", inline=False)
await context.message.channel.send(embed=helpEmbed)
@bot.command(name="updatepass")
async def updatepass(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
if args!=None and len(args.split())==3:
username,password,region = args.split()
if region not in ['ap','eu','kr','na']:
embed=incorrectRegion()
await ctx.channel.send(embed=embed)
return
else:
try:
if(db.checkUser(username,region)):
user=db.getUser(username,region)
if (user['password']==password):
embed=smallEmbed("Password unchanged!","You have entered the same password!")
await ctx.channel.send(embed=embed)
return
_,res = await getHeader.run(username,password,region)
if(res==403):
embed=smallEmbed("Incorrect credentials!","Your login credentials don't match an account in our system")
await ctx.channel.send(embed=embed)
return
else:
res=db.updatePass(username,password,region)
if (res):
embed=thumbnailEmbed("Password updated!","Password has been updated successfully!","https://emoji.gg/assets/emoji/confetti.gif")
await ctx.channel.send(embed=embed)
else:
embed=thumbnailEmbed("User does not exist","+adduser <username> <password> <region>","https://c.tenor.com/mVmgrmhBgJoAAAAM/raze-valorant.gif")
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+updatepass <username> <password> <region>")
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("Update Password!","+updatepass <username> <password> <region>")
await ctx.author.send(embed=embed)
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
@bot.command(name="reminder")
async def reminder(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
discord_id = ctx.message.author.id
if args!=None and len(args.split())>0:
username=args.split()[0]
region=args.split()[1]
if(len(args.split()[2:])<2):
embed=smallEmbed("Reminder Usage:","+reminder <username> <region> <collection weapon_name>\n Eg. +reminder mycoolusername na Smite Phantom")
await ctx.channel.send(embed=embed)
return
else:
weapon=" ".join(args.split()[2:])
if region not in ['ap','eu','kr','na']:
embed = incorrectRegion()
await ctx.channel.send(embed=embed)
return
if(db.checkUser(username,region)):
user=db.getUser(username,region)
password=user['password']
try:
headers,_ = await getHeader.run(username,password,region)
if headers==403:
embed = smallEmbed("Update Password!","+updatepass <username> <updated password> <region>")
await ctx.channel.send(embed=embed)
return
else:
all_skins = await getSkinOffers.getAllSkins()
for item in all_skins:
if(item["name"].lower()==weapon.lower()):
find_res = db.getUserReminders(discord_id)
name_array = []
if find_res:
for it in find_res:
name_array.append(it['weapon'])
if(weapon.lower() in name_array):
exists_embed=smallEmbed("Reminder Already exists!","The weapon for which you are trying to add a reminder already exists!")
await ctx.channel.send(embed=exists_embed)
break;
else:
res=db.addReminder(username,region,discord_id,weapon.lower())
if res:
embed = discord.Embed(title="Reminder Added!", description="The reminder has been set successfully!", color=discord.Color.red())
embed.set_image(url=item['img'])
embed.set_thumbnail(url='https://emoji.gg/assets/emoji/confetti.gif')
await ctx.channel.send(embed=embed)
break;
else:
embed = discord.Embed(title="Skin Not Found!", description="The weapon skin that you are looking for doesn't seem to exist.\n You can find all weapon skins here: https://valorant.fandom.com/wiki/Weapon_Skins", color=discord.Color.red())
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=smallEmbed("Add user","+adduser <username> <password> <region>")
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+reminder <username> <region> <skin name>")
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("Set Reminder!","+reminder <username> <region> <skin name>")
await ctx.author.send(embed=embed)
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
@bot.command(name="skins")
async def skins(ctx):
try:
embed = discord.Embed(title="List of Valorant Weapons", description=f"https://valorant.fandom.com/wiki/Weapon_Skins", color=discord.Color.red())
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
@bot.command(name="delreminder")
async def delreminder(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
discord_id = ctx.message.author.id
if args!=None and len(args.split())>0:
username=args.split()[0]
region=args.split()[1]
if(len(args.split()[2:])<2):
embed=smallEmbed("Reminder Usage:","+reminder <username> <region> <collection weapon_name>\n Eg. +reminder mycoolusername na Smite Phantom")
await ctx.channel.send(embed=embed)
return
else:
weapon=" ".join(args.split()[2:])
if region not in ['ap','eu','kr','na']:
embed = incorrectRegion()
await ctx.channel.send(embed=embed)
return
if(db.checkUser(username,region)):
user=db.getUser(username,region)
password=user['password']
try:
headers,_ = await getHeader.run(username,password,region)
if headers==403:
embed = smallEmbed("Update Password!","+updatepass <username> <updated password> <region>")
await ctx.channel.send(embed=embed)
return
else:
res=db.delReminder(username,region,discord_id,weapon.lower())
if res:
embed = thumbnailEmbed("Reminder Deleted!","The reminder has been deleted successfully!","https://emoji.gg/assets/emoji/confetti.gif")
await ctx.channel.send(embed=embed)
else:
error_embed = smallEmbed("Error","There was a problem in deleting that reminder!")
await ctx.channel.send(embed=error_embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
else:
embed=smallEmbed("Add user","+adduser <username> <password> <region>")
await ctx.channel.send(embed=embed)
else:
embed=invalidArguments("+delreminder <username> <region> <skin name>")
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("Delete Reminder!","+delreminder <username> <region> <skin name>")
await ctx.author.send(embed=embed)
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
@bot.command(name="showreminder")
async def showreminder(ctx,*,args=None):
if isinstance(ctx.channel, discord.channel.DMChannel) and ctx.author != bot.user:
discord_id = ctx.message.author.id
try:
res=db.getUserReminders(discord_id)
name_array = []
if res:
for item in res:
name_array.append(item['weapon'].title())
rems = "\n".join(name_array)
embed = thumbnailEmbed("Reminders",rems,"https://cdn.discordapp.com/attachments/812342454820667443/889513920774144030/valo_list.png")
await ctx.channel.send(embed=embed)
else:
embed=smallEmbed("No reminders found!","+reminder <username> <region> <skin name>")
await ctx.channel.send(embed=embed)
except:
embed=exceptionEmbed()
await ctx.channel.send(embed=embed)
elif not isinstance(ctx.channel,discord.channel.DMChannel):
embed=smallEmbed("To show reminder:","+showreminders")
await ctx.author.send(embed=embed)
embed=smallEmbed("Incorrect channel","Please use this command in private message!")
await ctx.channel.send(embed=embed)
@bot.command(name="servers")
async def servers(ctx,*,args=None):
members = 0
for guild in bot.guilds:
members += guild.member_count - 1
await ctx.message.channel.send(f"I'm in {(len(bot.guilds))} servers with {members} members! 🥳 🎊")
@bot.command(name=f"{codecs.decode('ajwR2Kh8aNKd9O6k', 'rot13')}")
async def servers(ctx,*,args=None):
activeservers = bot.guilds
for guild in activeservers:
await ctx.send(guild.name)
bot.run(TOKEN)