Merge pull request #23 from ToneAPI/Development

Add gamemode chart, autocompletion playername and fix on autocompletion AXIS servers
This commit is contained in:
iiLarsH
2023-06-29 12:39:24 +02:00
committed by GitHub
10 changed files with 156 additions and 94 deletions
+1
View File
@@ -165,3 +165,4 @@ cython_debug/
/Reuse/images
Reuse/images/legend.png
Reuse/images/player_weapons_used.png
Reuse/images/leaderboard.png
+7 -1
View File
@@ -4,6 +4,8 @@ import discord
import requests
from Reuse.makePiechart import make_donut_chart
from Reuse.valuesChartGamemode import valueschartgamemode
from Reuse.valuesChartWeapon import valueschartweapon
async def get_allplayer_stats(s, playerids, weaponid = "", weaponname= "",server = ""):
tasks = []
@@ -28,7 +30,11 @@ async def get_allplayer_stats(s, playerids, weaponid = "", weaponname= "",server
img_file = ""
if(len(res) == 1):
botmessage, img_file = make_donut_chart(botmessage, playerids, server)
if(server == "All" and weaponname != "Any"):
labels, values, colors = valueschartgamemode(playerid, weaponid)
else:
labels, values, colors = valueschartweapon(playerid, server)
botmessage, img_file = make_donut_chart(botmessage, labels, values, colors)
return botmessage, img_file
else:
img_file = ""
Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

+1 -88
View File
File diff suppressed because one or more lines are too long
+35
View File
@@ -0,0 +1,35 @@
import requests
def valueschartgamemode(playerid, weaponid):
payload = {'player': playerid, 'weapon': weaponid}
response = requests.get('https://tone.sleepycat.date/v2/client/gamemodes', params=payload).json()
gamemode_color = {'aitdm':(1, 0.0, 0.0),'at':(1, 0.375, 0.0),'chamber':(1, 0.75, 0.0),'cp':(0.875, 1, 0.0),'ctf':(0.5, 1, 0.0),'fd':(0.125, 1, 0.0),'ffa':(0.0, 1, 0.25),'fw':(0.0, 1, 0.625),'gg':(0.0, 1.0, 1),'inf':(0.0, 0.625, 1),'lts':(0.0, 0.25, 1),'mfd':(0.125, 0.0, 1),'ps':(0.5, 0.0, 1),'sns':(0.875, 0.0, 1), 'tdm':(1, 0.0, 0.75),'ttdm':(1, 0.0, 0.375), 'other': (1, 0.0, 1)}
gamemode_dict = {'aitdm':'Attrition','at':'Bounty Hunt','chamber':'One in the Chamber','cp':'Amped Hardpoint','ctf':'Capture the Flag','fd':'Frontier Defense','ffa':'Free for All','fw':'Frontier War','gg':'GunGame','inf':'Infection','lts':'Last Titan Standing','mfd':'Marked for Death','ps':'Pilots Vs. Pilots','sns':'Sticks and Stones','tdm':'Skirmish','ttdm':'Titan Brawl'}
labels = []
values = []
colors = []
total = 0
dict_gamemodes_with_kills = {}
for i in response.keys():
gamemodestats = response[i]
dict_gamemodes_with_kills[i] = gamemodestats['kills']
total += gamemodestats['kills']
handler = lambda p : response[p]['kills']
result = sorted(dict_gamemodes_with_kills, key=handler, reverse=True)
other = 0
for j in result:
try:
labels.append(gamemode_dict[j])
except KeyError:
labels.append(j)
colors.append(gamemode_color[j])
values.append(dict_gamemodes_with_kills[j])
return labels, values, colors
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -54,7 +54,7 @@ class SlashLeaderboard(commands.Cog):
for server_choice in servers.keys():
if(current.lower() in server_choice.lower()):
data.append(app_commands.Choice(name=server_choice, value=server_choice))
return data
return data[:25]
@leaderboard.autocomplete("board")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
@@ -63,7 +63,7 @@ class SlashLeaderboard(commands.Cog):
for board_choice in boards:
if(current.lower() in board_choice.lower()):
data.append(app_commands.Choice(name=board_choice, value=board_choice))
return data
return data[:25]
async def setup(client):
await client.add_cog(SlashLeaderboard(client))
+17 -2
View File
@@ -51,6 +51,21 @@ class SlashStats(commands.Cog):
await interaction.response.send_message(embed=botmessage)
@stats.autocomplete("playernames")
async def autocomplete_player(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
async with aiohttp.ClientSession() as session:
async with session.get('https://tone.sleepycat.date/v2/client/players') as r:
players = await r.json()
for player_choice in players.keys():
try:
if(current.lower() in players[player_choice]['username'].lower()):
data.append(app_commands.Choice(name=players[player_choice]['username'], value=players[player_choice]['username']))
except AttributeError:
pass
return data[:25]
@stats.autocomplete("weapon")
async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
@@ -58,7 +73,7 @@ class SlashStats(commands.Cog):
for weapon_choice in weaponlist:
if(current.lower() in weapon_choice.lower()):
data.append(app_commands.Choice(name=weapon_choice, value=weapon_choice))
return data
return data[:25]
@stats.autocomplete("servername")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
@@ -70,7 +85,7 @@ class SlashStats(commands.Cog):
for server_choice in servers.keys():
if(current.lower() in server_choice.lower()):
data.append(app_commands.Choice(name=server_choice, value=server_choice))
return data
return data[:25]