-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
180 lines (160 loc) · 6.91 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
import discord
from discord.ext import commands
import database as db
import aiohttp
from api import *
import re
import datetime
from util import *
from matplotlib import pyplot as plt
import numpy as np
from graph import *
import io
token = open("token.txt","r").readline()
client = discord.Client()
bot = commands.Bot(command_prefix="v.")
@bot.event
async def on_ready():
print("Bot connected.")
@bot.event
async def on_command_error(ctx,error):
if isinstance(error,commands.MissingRequiredArgument):
await ctx.send("Wrong command format")
#await ctx.message.delete()
@bot.command()
async def link(ctx,username,itag):
tag=re.sub("^#",'',itag)
data= await cred_validate(username,tag)
if data['status']=='200':
db.set_record(ctx.message.author.id,username,tag,data['data'])
await ctx.send(f"{ctx.message.author.mention} you are linked ☑")
elif data['status']=='404':
await ctx.send(data['message'])
else:
await ctx.send(data['message'])
#db.set_record(ctx.message.author.id,username,tag)
#db.get_record(ctx.message.author.id)
@bot.command()
async def rank(ctx, member: discord.Member=None):
if member is not None:
await ctx.send(f"{member.mention} hello")
else:
await ctx.send(ctx.message.author.mention)
'''
@bot.command()
async def status(ctx, region):
if region in ('eu', 'ap', 'na', 'kr'):
'''
@bot.command()
async def live(ctx,member:discord.Member):
details=db.get_record(member.id)
if details is None:
await ctx.send(f'{member.mention} has not linked their account')
else:
data=await live_match(details['display_name'],details['tag'])
if 'message' in data:
print("hello", data['message'])
await ctx.send(data['message'])
elif 'data' in data:
try:
embed=discord.Embed(title="")
gamemode=""
data2=data['data']
#await ctx.send(data2['current_selected_gamemode'])
if data2['current_state']=="MENUS":
if data2['current_selected_gamemode']=="":
gamemode="custom"
elif data2['current_selected_gamemode']=="ggteam":
gamemode="spike rush"
else:
gamemode=data2['current_selected_gamemode']
embed=discord.Embed(title="MENUS")
embed.set_author(name="{} #{}".format(details['display_name'],details['tag']))
embed.add_field(name="game mode", value=gamemode, inline=True)
embed.add_field(name="party size", value=data2['party_size'], inline=True)
embed.timestamp = datetime.datetime.utcnow()
embed.set_footer(text='\u200b')
await ctx.send(embed=embed)
else:
gamemode=data2['gamemode']
score=f"[{data2['score_ally_team']}:{data2['score_enemy_team']}]"
if data2["custom_game"]=="true":
sym="✅"
else:
sym="❌"
embed=discord.Embed(title=data2['current_state'], description=f"custom {sym}")
embed.set_thumbnail(url=gamemode_icons[gamemode])
embed.set_author(name="{} #{}".format(details['display_name'],details['tag']))
embed.add_field(name="game mode", value=f"{gamemode} {score}", inline=True)
embed.add_field(name='\u200b', value='\u200b',inline=True)
embed.add_field(name="MAP", value=data2['map'], inline=True)
embed.set_image(url=maps[data2['map']])
embed.timestamp = datetime.datetime.utcnow()
await ctx.send(embed=embed)
except Exception as e:
print(e)
else:
await ctx.send("SERVER ERROR")
@bot.command()
async def stats(ctx,member:discord.Member=None):
if member is None:
member=ctx.message.author
details=db.get_record(member.id)
if details is None:
await ctx.send(f'{member.mention} has not linked their account')
else:
p1=await statistics(details['display_name'],details['tag'])
p1['acc_level']=details['details']['account_level']
p1mmr=await mmr(details['display_name'],details['tag'],details['details']['region'])
if p1mmr['games_needed_for_rating']!=0:
rank="unranked"
description=""
else:
rank=p1mmr['currenttierpatched']
description = f"**{p1mmr['ranking_in_tier']}/100** RR | **{p1mmr['elo']}** ELO"
embed = discord.Embed(title=rank, description=description)
embed.set_thumbnail(url=p1["rankIconUrl"])
embed.set_author(name=p1['user'], icon_url=p1["avatarUrl"])
embed.add_field(name="K/D Ratio", value=p1["kd_ratio"])
embed.add_field(name="\u200b", value="\u200b")
embed.add_field(name="Aces", value=p1["aces"])
embed.add_field(name="Headshot %", value=p1["hs_pct"])
embed.add_field(name="\uFEFF", value="\uFEFF")
embed.add_field(name="Win %", value=p1["win_pct"])
embed.add_field(name="Time Played", value=p1["time_played"])
embed.add_field(name="\u200b", value="\u200b")
embed.add_field(name="Account Level",value=p1['acc_level'])
await ctx.send(embed=embed)
@bot.command()
async def history(ctx,member:discord.Member=None):
if member is None:
member=ctx.message.author
details=db.get_record(member.id)
if details is None:
await ctx.send(f'{member.mention} has not linked their account')
else:
p1=await mmr_history(details['display_name'],details['tag'],details['details']['region'])
if p1 is None:
await ctx.send("NOT PLACED")
else:
ratings=[]
for match in p1['data']:
ratings.append(match['mmr_change_to_last_game'])
embed = discord.Embed(title=f"{details['display_name']}'s match history", description=f"Current rank: **{p1['data'][0]['currenttierpatched']}**")
embed.add_field(name="Last game played",value=p1['data'][0]['date'])
#embed.add_field(name="matches",value=ratings)
plot(ratings)
image=discord.File("saved_figure.png",filename="saved_figure.png")
embed.set_image(url=f"attachment://saved_figure.png")
await ctx.send(file=image,embed=embed)
@bot.command()
async def match(ctx):
details=db.get_record(ctx.message.author.id)
if details is None:
await ctx.send(f'{ctx.message.author.mention} has not linked their account')
else:
try:
p1=await match(details['display_name'],details['tag'],details['details']['region'])
except Exception as e:
print(e)
bot.run(token)