-
Notifications
You must be signed in to change notification settings - Fork 4
/
WoTBlitz.py
214 lines (170 loc) · 8.33 KB
/
WoTBlitz.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
import json
import requests
from discord import Embed, Member
from discord.ext import commands
import discord
import datetime
import asyncio
client = commands.Bot(command_prefix=">")
client.remove_command("help")
login_dict = {
}
async def status_task():
while True:
await client.change_presence(activity=discord.Game(name="🍕 Eating pizza..."))
await asyncio.sleep(15)
await client.change_presence(activity=discord.Game(name="🍹 Drinking smoothies..."))
await asyncio.sleep(15)
await client.change_presence(activity=discord.Game(name="🧀 Try >stats..."))
await asyncio.sleep(15)
'''
------------------------------------------------------------------------------------------------------------------------
'''
def get_account_id(player, server):
data = requests.get(
f"https://api.wotblitz.{server}/wotb/account/list/?application_id=95523cc25e231e510f678729e21a9e10&search={player}")
json_data = json.loads(data.text)
info = json_data['data']
account_id = info[0]['account_id']
return account_id
def get_clan_id(account_id, server):
data = requests.get(
f"https://api.wotblitz.{server}/wotb/clans/accountinfo/?application_id=95523cc25e231e510f678729e21a9e10&account_id={account_id}")
json_data = json.loads(data.text)
total_data = json_data['data']
player_id_category = total_data[f'{account_id}']
if player_id_category is None:
clan_id = None
else:
clan_id = player_id_category['clan_id']
return clan_id
'''
------------------------------------------------------------------------------------------------------------------------
'''
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
client.loop.create_task(status_task())
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Please pass in all required arguments.")
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("This command does not exist / Invalid command used")
'''
------------------------------------------------------------------------------------------------------------------------
'''
@client.command()
async def login(ctx, player=None, *, server=None):
try:
for key in login_dict:
if key == ctx.author.id:
await ctx.send("You are already logged in.")
break
login_dict[f'{ctx.author.id}'] = player, server
await ctx.send(f"In Game Name: {player} | Server: {server}")
print(login_dict)
except:
await ctx.send("Try: `>login [IGN] [SERVER]`")
@client.command()
async def logout(ctx):
try:
for key in login_dict:
if key == ctx.author.id:
del login_dict[f"{ctx.author.id}"]
break
await ctx.send("Successfully logged out")
print(login_dict)
except Exception:
await ctx.send("You need to first login before you can logout!")
@client.command()
async def stats(ctx, player=None, *, server=None):
if player is None and server is None:
try:
for key in login_dict:
if key == f"{ctx.author.id}":
print(login_dict[key])
player = login_dict[key][0]
print(player)
server = login_dict[key][1]
else:
print(key)
except:
await ctx.send("Error has occured, please contact bot owner. stampixel")
if server is None:
await ctx.send("Please input a server")
else:
print(server)
if server == "eu" or server == "Eu" or server == "EU":
server = "eu"
elif server == "na" or server == "NA":
server = "com"
elif server == "ru" or server == "Ru" or server == "RU":
server = "ru"
elif server == "asia" or server == "Asia" or server == "ASIA":
server = "asia"
else:
await ctx.send("please input a valid server")
if player is None:
await ctx.send("Please input a player.")
else:
try:
account_id = get_account_id(player=player, server=server)
data = requests.get(
f"https://api.wotblitz.{server}/wotb/account/info/?application_id=95523cc25e231e510f678729e21a9e10&account_id={account_id}")
json_data = json.loads(data.text)
# json subcatagory scraping
total_data = json_data['data']
player_id_category = total_data[f'{account_id}']
player_nickname = player_id_category['nickname']
statistic = player_id_category['statistics']
player_stats = statistic['all']
total_wins = player_stats['wins']
total_losses = player_stats['losses']
total_random_battles = player_stats['battles']
total_frags = player_stats['frags']
damage_dealt = player_stats['damage_dealt']
damage_received = player_stats['damage_received']
player_last_battle = datetime.datetime.fromtimestamp(player_id_category['last_battle_time'])
account_creation_date = datetime.datetime.fromtimestamp(player_id_category['created_at'])
embed = Embed(title=f"`{player_nickname}`'s Career Stats",
description="Here are the stats of the player's life time career on WoTBlitz:",
colour=discord.Colour.blurple())
winrate = float("{0:.2f}".format(total_wins / total_random_battles * 100))
damage_ratio = float("{0:.2f}".format(damage_dealt / damage_received))
embed.set_author(name=ctx.message.author, icon_url=ctx.author.avatar_url)
embed.add_field(name=':triangular_flag_on_post: **Battles**', value=f'┕`{total_random_battles}`',
inline=True)
embed.add_field(name=':100: **Wins**', value=f'┕`{total_wins}`', inline=True)
embed.add_field(name=':flag_white: **Losses**', value=f'┕`{total_losses}`', inline=True)
embed.add_field(name=':dart: **Winrate**', value=f'┕`{winrate}%`', inline=True)
embed.add_field(name=':no_entry_sign: **Kills/Frags**', value=f'┕`{total_frags}`', inline=True)
embed.add_field(name=':hourglass_flowing_sand: **Damage Ratio**', value=f'┕`{damage_ratio}`', inline=True)
embed.add_field(name=f":clock1: Created At: `{account_creation_date.strftime('%Y-%m-%d %H:%M:%S')}`",
value='==================================', inline=False)
clan_id = get_clan_id(account_id=account_id, server=server)
if clan_id is None:
embed.add_field(name=':x: **ERROR**', value=f'┕`{player_nickname}` is either not in a clan or an '
f'error has occured. Please contact __**[stampixel]('
f'https://discords.com/bio/p/stampixel)**__ if you have any questions '
f'or concerns.', inline=False)
embed.set_footer(
text=f"Server: {server} | ID Blitz Account: {account_id} | Last Battle: {player_last_battle.strftime('%Y-%m-%d %H:%M:%S')}")
else:
data = requests.get(
f"https://api.wotblitz.{server}/wotb/clans/info/?application_id=95523cc25e231e510f678729e21a9e10&clan_id={clan_id}")
json_data = json.loads(data.text)
total_data = json_data['data']
clan_id_category = total_data[f'{clan_id}']
clan_name = clan_id_category['name']
member_count = clan_id_category['members_count']
embed.add_field(name=':trident: **Clan Name**', value=f'┕`{clan_name}`', inline=True)
embed.add_field(name=':pencil: **Member Count**', value=f'┕`{member_count}`', inline=True)
embed.set_footer(
text=f"Server: {server} | ID Blitz Account: {account_id} | Last Battle: {player_last_battle.strftime('%Y-%m-%d %H:%M:%S')}")
await ctx.send(embed=embed)
except IndexError:
await ctx.send(f"Username `{player}` not found.")
client.run('TOKEN')