· 6 years ago · Nov 08, 2019, 10:12 AM
1import discord
2from discord.ext import commands
3import random
4import asyncio
5import io
6import re
7import subprocess
8import os
9import sys
10import requests
11from subprocess import check_output
12import mysql.connector
13mydb = mysql.connector.connect(
14host="remotemysql.com",
15user="yMtr9Xyul8",
16passwd="s6OSlihgQe",
17database="yMtr9Xyul8"
18)
19cursor=mydb.cursor()
20bot = commands.Bot(command_prefix='$')
21def read_token():
22 with open("token.txt", "r") as f:
23 lines = f.readlines()
24 return lines[0].strip()
25client = discord.Client()
26AllowedChannels = ["bot-spam"]
27Admins = ["Remeku#8640", "SYNCR3AL#3340"]
28token = read_token()
29API = "RGAPI-6190f3ec-08b3-4b49-bf72-010438a8fb8a"
30def getSummoner(region,summoner,API):
31 URL = f"https://{region}.api.riotgames.com/lol/summoner/v4/summoners/by-name/{summoner}?api_key={API}"
32 response=requests.get(URL)
33 return response.json()
34def getGameInfo(region,summoner,API):
35 URL= f"https://{region}.api.riotgames.com/lol/spectator/v4/active-games/by-summoner/{summoner}?api_key={API}"
36 response=requests.get(URL)
37 return response.json()
38def getLeagueInfo(region,summonerID,API):
39 URL = f"https://{region}.api.riotgames.com/lol/league/v4/positions/by-summoner/{summonerID}?api_key={API}"
40 response=requests.get(URL)
41 return response.json()
42
43@bot.event
44async def on_member_update(before, after):
45 if before.nick!=after.nick:
46 ###########################
47 #######SQL CONNECTOR#######
48 ###########################
49 mydb = mysql.connector.connect(
50 host="remotemysql.com",
51 user="yMtr9Xyul8",
52 passwd="s6OSlihgQe",
53 database="yMtr9Xyul8"
54 )
55 cursor = mydb.cursor()
56 ###########################
57 #######SQL CONNECTOR#######
58 ###########################
59
60
61 sql = f"INSERT INTO NickChange (before_sql,after_sql) VALUES (%s,%s)"
62 val = (before.nick, after.nick)
63 cursor.execute(sql,val)
64 mydb.commit()
65@bot.event
66async def on_ready():
67 mydb = mysql.connector.connect(
68 host="remotemysql.com",
69 user="yMtr9Xyul8",
70 passwd="s6OSlihgQe",
71 database="yMtr9Xyul8"
72 )
73 cursor = mydb.cursor()
74 for guild in bot.guilds:
75 '''channel = discord.utils.get(guild.channels, name="bot-spam")
76 msg = await channel.send("Loading\n|------|")
77 await asyncio.sleep(random.randint(1,15) / 10)
78 await msg.edit(content="Loading\n|█-----|")
79 await asyncio.sleep(random.randint(1,15) / 10)
80 await msg.edit(content="Loading\n|██----|")
81 await asyncio.sleep(random.randint(1,15) / 10)
82 await msg.edit(content="Loading\n|███---|")
83 await asyncio.sleep(random.randint(1,15) / 10)
84 await msg.edit(content="Loading\n|████--|")
85 await asyncio.sleep(random.randint(1,15) / 10)
86 await msg.edit(content="Loading\n|█████-|")
87 await asyncio.sleep(random.randint(1,15) / 10)
88 await msg.edit(content="Loading\n|██████|")
89 await asyncio.sleep(random.randint(1,15) / 10)
90 await msg.edit(content="Loaded!")
91 await asyncio.sleep(0.5)
92 await msg.delete()'''
93 game = discord.Game("with Richardo Milos")
94 await bot.change_presence(status=discord.Status.online, activity=game)
95 print('Logged in as')
96 print(bot.user.name)
97 print(bot.user.id)
98 print('------')
99 AllGuilds = bot.fetch_guilds()
100 async for x in AllGuilds:
101 cursor.execute(f"CREATE TABLE IF NOT EXISTS ID{str(x.id)} ("
102 f"id INT AUTO_INCREMENT PRIMARY KEY, "
103 f"discord_id MEDIUMTEXT,"
104 f"serverid VARCHAR(255), "
105 f"username VARCHAR(255))")
106 CurrentGuild= bot.get_guild(x.id)
107 for member in CurrentGuild.members:
108 cursor.execute(f"SELECT discord_id FROM ID{str(x.id)}")
109 results = cursor.fetchall()
110 if not member.id in results:
111 sql = f"INSERT INTO ID{str(x.id)} (discord_id,serverid,username) VALUES (%s,%s,%s)"
112 values = (member.id,str(x.id), str(member))
113 cursor.execute(sql, values)
114 mydb.commit()
115 cursor.execute(f"SELECT discord_id FROM all_users")
116 results = cursor.fetchall()
117 if not str(f"('{member.id}',)") in str(results):
118 print(member.id)
119 print(results)
120 sql = f"INSERT INTO all_users (discord_id,username,point_progress,points,total_messages_sent,level,bad_messages_sent,bad_points) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)"
121 values = (member.id,str(member),0,0,0,0,0,0)
122 cursor.execute(sql, values)
123 mydb.commit()
124
125@bot.event
126async def on_message(ctx):
127 ###########################
128 #######SQL CONNECTOR#######
129 ###########################
130 mydb = mysql.connector.connect(
131 host="remotemysql.com",
132 user="yMtr9Xyul8",
133 passwd="s6OSlihgQe",
134 database="yMtr9Xyul8"
135 )
136 cursor = mydb.cursor()
137 ###########################
138 #######SQL CONNECTOR#######
139 ###########################
140 cursor.execute(f"SELECT discord_id FROM all_users")
141 results = cursor.fetchall()
142 for row in results:
143 if str(row[0]) == str(ctx.author.id):
144 print(ctx.author.id)
145 print('Matching success!')
146 cursor.execute(f"SELECT point_progress FROM all_users WHERE discord_id={str(ctx.author.id)}")
147 result=cursor.fetchone()
148 for row in result:
149 if row <5:
150 print(f"current progression: {row}/5, adding a progression point.")
151 cursor.execute(f"UPDATE `all_users` SET `point_progress` = {row+1} WHERE discord_id={str(ctx.author.id)}")
152 mydb.commit()
153 if row >=5:
154 print(f"current progression: {row}/5, resetting progression to 0 and adding a point.")
155 cursor.execute(f"UPDATE `all_users` SET `point_progress` = 0 WHERE discord_id={str(ctx.author.id)}")
156 cursor.execute(f"SELECT points FROM all_users WHERE discord_id={str(ctx.author.id)}")
157 result = cursor.fetchone()
158 for row in result:
159 cursor.execute(f"UPDATE `all_users` SET `points` = {row+1} WHERE discord_id={str(ctx.author.id)}")
160 mydb.commit()
161 await bot.process_commands(ctx)
162 #'''print(row[0])'''
163 '''cursor.execute(f"SELECT discord_id FROM all_users")
164 results = cursor.fetchall()
165 print(f"('{ctx.author.id}',)")
166 for x in results:
167 print(x)
168 if ctx.author.id in results:
169 sql = f"SELECT point_progress FROM all_users WHERE discord_id = {ctx.author.id}"
170 cursor.execute(sql)
171 result=cursor.fetchone()
172 print(sql)
173 print(results)
174 print(results[0])
175 if result > 5:
176 sql=f"UPDATE 'all_users` SET `point_progress` = '0' WHERE ID={ctx.author.id}"
177 cursor.execute(sql)
178 sql=f"SELECT points FROM all_users WHERE discord_id={ctx.author.id}"
179 cursor.execute(sql)
180 result=cursor.fetchone()
181 sql=f"UPDATE 'all_users` SET `points` = '{int(result)+1}' WHERE discord_id={ctx.author.id}"'''
182
183
184@bot.command()
185async def rip(ctx):
186 url = "nigger"
187 await ctx.send(url)
188
189@bot.command()
190async def f(ctx):
191 url = "https://media.discordapp.net/attachments/556962926137835526/557174939468300288/B1vdCCCBBEHBAAAAAElFTkSuQmCC.png"
192 await ctx.send(url)
193
194
195
196@bot.command()
197async def infinite(ctx):
198 lyrics = '''Infinite, in infinite power
199Infinite, in infinite power
200Infinite, in infinite power
201(power, power, power)
202(Infinite power.)
203Infinite, in infinite power
204Infinite, in infinite power
205Infinite, in infinite power
206(power, power, power)
207(Infinite power.)
208(power, power, power, power, power,
209power, power, power, power, power, power)
210Infinite power!
211Infinite power
212Infinite power
213Infinite power
214Infinite power!
215(Infinite, in infinite)
216(Infinite, in infinite power)
217(Infinite, in infinite)
218(Infinite, in infinite power)
219(Infinite, in infinite)
220(Infinite, in infinite power)
221(Infinite, in infinite)
222(Infinite, in infinite power)
223Infinite, in infinite power
224Infinite, in infinite power
225Infinite, in infinite power
226(power, power, power, power)
227(power, power, power, power, power,
228power, power, power, power, power, power)
229Infinite power!
230(Infinite power)
231(Infinite power)'''
232 await ctx.send(lyrics)
233
234@bot.command()
235async def sometime(ctx):
236 msg = await ctx.send("Sometime")
237 await asyncio.sleep(random.randint(1, 15) / 10)
238 await msg.edit(content="It")
239 await asyncio.sleep(random.randint(1, 15) / 10)
240 await msg.edit(content="Do")
241 await asyncio.sleep(random.randint(1, 15) / 10)
242 await msg.edit(content="Be")
243 await asyncio.sleep(random.randint(1, 15) / 10)
244 await msg.edit(content="Like")
245 await asyncio.sleep(random.randint(1, 15) / 10)
246 await msg.edit(content="DAT")
247 await asyncio.sleep(0.5)
248 await msg.delete()
249
250@bot.command()
251async def test(ctx, arg):
252 await ctx.send(arg)
253
254'''@bot.command()
255async def register(ctx, password, password2):
256 cursor.execute("SELECT name FROM users")
257 results = cursor.fetchall()
258 if not str(f"('{ctx.author}',)") in str(results):
259 if password == password2:
260 await ctx.send(results[0]) # Outputs ('Remeku#8640',)
261 await ctx.send(str(f"('{ctx.author}',)")) #Outputs ('Remeku#8640',)
262 sql="INSERT INTO users (name,password) VALUES (%s,%s)"
263 values=(str(ctx.author),str(password))
264 cursor.execute(sql,values)
265 mydb.commit()
266 await ctx.send("User sucessfully registered!")
267 else:
268 await ctx.send("Please enter matching passwords.")
269 else:
270 await ctx.send("User already registered.")'''
271
272@bot.command()
273async def users(ctx, ID):
274 ###########################
275 #######SQL CONNECTOR#######
276 ###########################
277 mydb = mysql.connector.connect(
278 host="remotemysql.com",
279 user="yMtr9Xyul8",
280 passwd="s6OSlihgQe",
281 database="yMtr9Xyul8"
282 )
283 cursor = mydb.cursor()
284 ###########################
285 #######SQL CONNECTOR#######
286 ###########################
287 if str(ctx.author) in str(Admins):
288 cursor.execute(f"SELECT username FROM ID{ID}")
289 result=cursor.fetchall()
290 for x in result:
291 await ctx.send(x)
292
293@bot.command()
294async def xd(ctx, lmao, kek):
295 await ctx.send(f"{lmao} {kek}")
296@bot.command()
297async def members(ctx):
298 for guild in bot.guilds:
299 for member in guild.members:
300 print(str(member))
301
302@bot.command()
303async def login(ctx):
304 mydb = mysql.connector.connect(
305 host="remotemysql.com",
306 user="yMtr9Xyul8",
307 passwd="s6OSlihgQe",
308 database="yMtr9Xyul8"
309 )
310 cursor = mydb.cursor()
311 print("omega")
312@bot.command()
313async def mypoints(ctx):
314 ###########################
315 #######SQL CONNECTOR#######
316 ###########################
317 mydb = mysql.connector.connect(
318 host="remotemysql.com",
319 user="yMtr9Xyul8",
320 passwd="s6OSlihgQe",
321 database="yMtr9Xyul8"
322 )
323 cursor = mydb.cursor()
324 ###########################
325 #######SQL CONNECTOR#######
326 ###########################
327 cursor.execute(f"SELECT points FROM all_users WHERE discord_id={str(ctx.author.id)}")
328 result=cursor.fetchone()
329 for row in result:
330 await ctx.send(f"User {ctx.author.mention} has a total of {row} points!")
331@bot.command()
332async def top(ctx):
333 ###########################
334 #######SQL CONNECTOR#######
335 ###########################
336 mydb = mysql.connector.connect(
337 host="remotemysql.com",
338 user="yMtr9Xyul8",
339 passwd="s6OSlihgQe",
340 database="yMtr9Xyul8"
341 )
342 cursor = mydb.cursor()
343 ###########################
344 #######SQL CONNECTOR#######
345 ###########################
346 sql=cursor.execute(f"SELECT username,points FROM all_users ORDER BY points DESC LIMIT 5")
347 cursor.execute(sql)
348 result=cursor.fetchall()
349 embed=discord.Embed(title="Points Leaderboard", description="The top 5 users with the most points.")
350 for row in result:
351 number=1
352 embed.add_field(name=f"{row[0]}", value=f"{row[1]} points")
353 await ctx.send(embed=embed)
354
355
356@bot.command()
357async def give(ctx,mention,ammount):
358 if str(ctx.author) in Admins:
359 ###########################
360 #######SQL CONNECTOR#######
361 ###########################
362 mydb = mysql.connector.connect(
363 host="remotemysql.com",
364 user="yMtr9Xyul8",
365 passwd="s6OSlihgQe",
366 database="yMtr9Xyul8"
367 )
368 cursor = mydb.cursor()
369 ###########################
370 #######SQL CONNECTOR#######
371 ###########################
372 id=re.sub("<@", "", mention)
373 id=re.sub(">", "", id)
374 id=re.sub("!","",id)
375 cursor.execute(f"SELECT points FROM all_users WHERE discord_id={str(id)}")
376 result = cursor.fetchone()
377 for row in result:
378 cursor.execute(f"UPDATE `all_users` SET `points` = {row + int(ammount)} WHERE discord_id={str(id)}")
379 mydb.commit()
380 await ctx.send("Points have been added!")
381 else:
382 await ctx.send(f"User {ctx.author} is not an Admin.")
383@bot.command()
384async def remove(ctx,mention,ammount):
385 if str(ctx.author) in Admins:
386 ###########################
387 #######SQL CONNECTOR#######
388 ###########################
389 mydb = mysql.connector.connect(
390 host="remotemysql.com",
391 user="yMtr9Xyul8",
392 passwd="s6OSlihgQe",
393 database="yMtr9Xyul8"
394 )
395 cursor = mydb.cursor()
396 ###########################
397 #######SQL CONNECTOR#######
398 ###########################
399 id=re.sub("<@", "", mention)
400 id=re.sub(">", "", id)
401 id=re.sub("!","",id)
402 cursor.execute(f"SELECT points FROM all_users WHERE discord_id={str(id)}")
403 result = cursor.fetchone()
404 for row in result:
405 cursor.execute(f"UPDATE `all_users` SET `points` = {row - int(ammount)} WHERE discord_id={str(id)}")
406 mydb.commit()
407 await ctx.send("Points have been removed!")
408 else:
409 await ctx.send(f"User {ctx.author} is not an Admin")
410
411@bot.command()
412async def profile(ctx,mention : discord.Member):
413 ###########################
414 #######SQL CONNECTOR#######
415 ###########################
416 mydb = mysql.connector.connect(
417 host="remotemysql.com",
418 user="yMtr9Xyul8",
419 passwd="s6OSlihgQe",
420 database="yMtr9Xyul8"
421 )
422 cursor = mydb.cursor()
423 ###########################
424 #######SQL CONNECTOR#######
425 ###########################
426 cursor.execute(f"SELECT username,points,total_messages_sent,level,bad_points FROM all_users WHERE discord_id={mention.id}")
427 result = cursor.fetchall()
428 embed = discord.Embed(title="User Profile",color=discord.Color(0x700000),description="User information")
429 for row in result:
430 embed.set_thumbnail(url=str(mention.avatar_url))
431 embed.add_field(name="Username", value=f"{str(row[0])}")
432 embed.add_field(name="Points", value=f"{str(row[1])}")
433 embed.add_field(name="Total messages", value=f"{str(row[2])}")
434 embed.add_field(name="Level", value=f"{str(row[3])}")
435 embed.add_field(name="Bad points", value=f"{str(row[4])}")
436 await ctx.send(embed=embed)
437
438@bot.command()
439async def livegame(ctx,summoner,region):
440
441 if region == "EUNE":
442 region="EUN1"
443 if region == "EUW":
444 region=="EUW1"
445 responseJSON = getSummoner(region,summoner,API)
446 if not responseJSON['id']:
447 await ctx.send("PLAYER DON'T EXIST NIGGER")
448 ID=responseJSON['id']
449 ID=str(ID)
450 embed = discord.Embed(title="Live game", description="Blue team",colour=discord.Colour(0x5ff))
451 responseJSON = getGameInfo(region,ID,API)
452 i=0
453 if len(responseJSON) > 0:
454 while i<5:
455 participants = responseJSON['participants'][i]['summonerName']
456 participants1 = str(participants)
457 participants1 = re.sub("{'","",participants1)
458 participants1 = re.sub("'}","",participants1)
459 summonerID = responseJSON['participants'][i]['summonerId']
460 summonerID = str(summonerID)
461 leagueResponse = getLeagueInfo(region,summonerID,API)
462 if len(leagueResponse) > 0:
463 leagueRank = leagueResponse[0]['tier']
464 leagueRankNumber = leagueResponse[0]['rank']
465 leagueWins = leagueResponse[0]['wins']
466 leagueLosses = leagueResponse[0]['losses']
467 WinRate = leagueWins/(leagueWins+leagueLosses)*100
468 WinRate = int(WinRate)
469 embed.add_field(name={participants1}, value=f"{leagueRank} {leagueRankNumber} {WinRate}% WR")
470 i+=1
471 else:
472 embed.add_field(name={participants1}, value=f"UNRANKED")
473 i += 1
474 else:
475 embed.add_field(name="User not currently in game!", value="")
476 await ctx.send(embed=embed)
477
478 embed = discord.Embed(title="Live game", description="Red team", colour=discord.Colour(0xff1200))
479 if len(responseJSON) > 0:
480 while i < 10:
481 participants = responseJSON['participants'][i]['summonerName']
482 participants1 = str(participants)
483 participants1 = re.sub("{'", "", participants1)
484 participants1 = re.sub("'}", "", participants1)
485 summonerID = responseJSON['participants'][i]['summonerId']
486 summonerID = str(summonerID)
487 leagueResponse = getLeagueInfo(region, summonerID, API)
488 if len(leagueResponse) > 0:
489 leagueRank = leagueResponse[0]['tier']
490 leagueRankNumber = leagueResponse[0]['rank']
491 leagueWins = leagueResponse[0]['wins']
492 leagueLosses = leagueResponse[0]['losses']
493 WinRate = leagueWins / (leagueWins + leagueLosses) * 100
494 WinRate = int(WinRate)
495 embed.add_field(name={participants1}, value=f"{leagueRank} {leagueRankNumber} {WinRate}% WR")
496 i += 1
497 else:
498 embed.add_field(name={participants1}, value=f"UNRANKED")
499 i += 1
500 else:
501 embed.add_field(name="User not currently in game!", value="")
502 await ctx.send(embed=embed)
503bot.run(token)