Merge pull request #11 from ToneAPI/Development

Development to main, feature rehaul and slash commands
This commit is contained in:
iiLarsH
2023-05-05 17:45:52 +02:00
committed by GitHub
15 changed files with 1037 additions and 325 deletions
+15
View File
@@ -1,4 +1,5 @@
from discord.ext import commands
from discord import app_commands
import discord
import os
import asyncio
@@ -16,9 +17,23 @@ async def load():
if filename.endswith(".py"):
await client.load_extension(f"cogs.{filename[:-3]}")
async def slashload():
for filename in os.listdir("./slashcogs"):
if filename.endswith(".py"):
await client.load_extension(f"slashcogs.{filename[:-3]}")
@client.command()
async def sync(ctx):
if ctx.message.author.id == 262672220260663297:
synced = await client.tree.sync()
print(f'You synced {str(len(synced))} commands')
else:
await ctx.send('You must be the botowner to use this command!')
async def main():
async with client:
await load()
await slashload()
await client.start(discordtoken.get())
asyncio.run(main())
+35
View File
@@ -0,0 +1,35 @@
import discord
from discord.ext import commands
class Changelog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Changlog.py is ready")
@commands.command()
async def changelog(self, ctx):
botmessage = str(
"Welcome to V1.1 of Sonar, we have lots to discuss because alot has changed or got added.\n\n"+
"-change 1, !stats and !compare arent 2 different functions anymore but became 1 function,\n"+
"so now you can do !stats <playername>, <playername>, <weapon>, or for those who like to write !compare this still works aswell.\n\n"+
"-change 2, !stats, !lb (!leaderboard) got <server> filters so now its possible to see your standing in a server.\n\n"
"-change 3, All currently existing commands did get an overhaul to make them less restrictive to people, so you no longer need to write wingman_elite,\n"+
"you can now do wingman elite or elite to get the wingman elite as filter, servers do have the same principle\n\n"+
"-change 4, clearer error message\n\n"+
"-change 5, All currently existing commands did get a slash command counterpart\n\n"+
"Thanks for reading and goodluck increasing those stats"
)
await ctx.send(f"```{botmessage}```")
async def setup(client):
await client.add_cog(Changelog(client))
-131
View File
@@ -1,131 +0,0 @@
import discord
from discord.ext import commands
import requests
class Compare(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("compare.py is ready")
@commands.command()
async def compare(self, ctx, *message):
listofpnameid = {}
for i in range(len(message)):
playername = message[i].replace(",", "")
playerid = self.getplayerid(playername)
listofpnameid[playername] = playerid
weaponid = ""
weaponname = ""
listofplayerids = []
for w in listofpnameid:
if(listofpnameid[w] == 'None'):
weaponid = self.getweaponid(w)
weaponname = w
listofpnameid[w] = weaponid
else:
listofplayerids.append(listofpnameid[w])
botmessage = ""
listofstats = []
for p in listofplayerids:
stats = self.getstats(p, weaponid, weaponname)
listofstats.append(stats)
divider = str("\n --------------- \n")
botmessage = divider.join(listofstats)
await ctx.send(f'```{botmessage}```')
def getplayerid(self, playername):
playerid = "None"
payload = str("username=") + playername
response = requests.get('https://northstar.tf/accounts/lookup_uid', params=payload).json()
if (response['matches'] != None):
playerid = response['matches'][0]
return str(playerid)
def getweaponid(self, weaponname):
response = requests.get('https://tone.sleepycat.date/v2/client/weapons').json()
r = response.keys()
weapon_dict = {'execution': 'human_execution',
'mp_weapon_car': 'car',
'mp_weapon_defender': 'charge_rifle',
'mp_weapon_doubletake': 'double_take',
'mp_weapon_epg': 'epg',
'mp_weapon_hemlok_smg': 'volt',
'mp_weapon_lstar': 'lstar',
'mp_weapon_r97':'r97',
'mp_weapon_rspn101': 'r-201',
'mp_weapon_smart_pistol': 'smart_pistol',
'mp_weapon_sniper': 'kraber',
'mp_weapon_vinson': 'flatline',
'mp_weapon_autopistol': 're-45_auto',
'mp_weapon_alternator_smg': 'alternator',
'mp_weapon_frag_grenade': 'frag_grenade',
'mp_weapon_g2': 'g2',
'mp_weapon_lmg': 'spitfire',
'mp_weapon_smr': 'smr',
'mp_weapon_softball': 'softball',
'mp_weapon_thermite_grenade': 'firestar',
'pilot_emptyhanded': 'melee',
'mp_weapon_mastiff': 'masstiff',
'mp_weapon_mgl': 'mgl',
'mp_weapon_rspn101_og': 'r-101',
'mp_weapon_wingman': 'wingman',
'invalid': 'invalid',
'mp_weapon_arc_launcher': 'thunderbolt',
'mp_weapon_dmr': 'dmr',
'mp_weapon_grenade_electric_smoke': 'electric_smoke',
'mp_weapon_pulse_lmg': 'cold_war',
'mp_weapon_satchel': 'satchel',
'mp_weapon_shotgun': 'eva-8_auto',
'mp_weapon_shotgun_pistol': 'mozambique',
'mp_weapon_wingman_n': 'wingman_elite',
'mp_weapon_grenade_gravity': 'gravity_star',
'mp_weapon_grenade_sonar': 'pulse_blade',
'mp_weapon_rocket_launcher': 'archer',
'outOfBounds': 'outOfBounds',
'mind_crime': 'mind_crime',
'mp_weapon_esaw': 'devotion',
'fall': 'fall',
'mp_weapon_semipistol': 'p2016',
'mp_weapon_grenade_emp': 'arc_grenade',
'mp_weapon_hemlok': 'hemlok',
'melee_pilot_emptyhanded': 'melee',
'phase_shift': 'phase_shift'
}
weaponid = ""
for i in r:
if(i in weapon_dict.keys()):
if (weaponname.lower() == weapon_dict[i]):
weaponid = i
break
return weaponid
def getstats(self, playerid, weaponid = "", weaponname = ""):
payload = {'player': playerid, 'weapon': weaponid}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
killstats = response[playerid]
botmessage = str("Playername: " + killstats['username'] + '\n' + "Kills : " + str(killstats['kills']) + '\n' )
if(weaponid != ""):
deaths=killstats['deaths_while_equipped']
if(deaths == 0):
deaths = 1;
botmessage += str("Deaths : " + str(killstats['deaths_while_equipped'])) + '\n' + str("Weapon : " + weaponname) + '\n' + str(str("weapon KD : " + str("{:0.2f}".format(killstats['kills']/deaths))))
else:
deaths=killstats['deaths']
if(deaths == 0):
deaths = 1;
botmessage = botmessage + str("Deaths : " + str(killstats['deaths'])) + '\n' + str("KD : " + str("{:0.2f}".format(killstats['kills']/deaths)))
return botmessage
async def setup(client):
await client.add_cog(Compare(client))
+24 -15
View File
@@ -13,30 +13,39 @@ class Help(commands.Cog):
async def help(self, ctx, message="all"):
botmessage = ""
if(message == "all"):
botmessage = str("To get further information about a command do: \n!help <command> \n" +
botmessage = str("To get further information about a command do: \n!help <command> \n------------------- \n" +
"The commands you can get information on are: \n" +
"roll \n" +
"ping \n" +
"compare \n" +
"stats \n" +
"leaderboard \n"+
"changelog : Gives all the information about the changes and updates.\n"
"roll : Rolls a number between 1 and 100. \n" +
"ping : Shows latency. \n" +
"stats : Shows stats collected by ToneAPI. \n" +
"leaderboard : Shows a leaderboard of stats. \n"+
"slashcommands: This explains what slash commands are, if you used slash commands before this isnt usefull\n"
"------------------- \n"
"if this help command doesnt help you or you have suggestions for future commands, ping or dm me @lars#1029")
elif(message == "changelog"):
botmessage = str("!changelogs is a command that gives you all the recent changes and updates")
elif(message == "roll"):
botmessage = str("!roll is a command that rolls a number between 1 and 100, with a rating")
elif(message == "ping"):
botmessage = str("!ping gives the latency between you and the bot")
elif(message == "compare"):
botmessage = str("!compare takes multiple playernames and 1 weapon to compare these players \n"+
"Example: \n!compare iilars, legonzaur, okvdai, kraber \n!compare <playername>, <playername>, <playername>, <weaponname> \nA weapon doesnt need to be specified")
elif(message == "stats"):
botmessage = str("!stats takes 1 playername and 1 weapon name to show this players stats\n"+
"Example: \n!stats iilars, kraber \n!stats <playername>, <weaponname> \nA weapon doesnt need to be specified\n"+
"For those wondering why the kd with a weapon doesnt match the webclient, de webclient takes kills with a weapon and deaths to that weapon and this bot takes kills with weapon and deaths while weapon is held")
botmessage = str("!stats takes playername(s), Optional: weaponname, servername\n"+
"Example: \n!stats iilars, kraber, fvnkhead's 3v3 \n!stats <playername>, <weaponname>, <servername> \nA weapon or server doesnt need to be specified, because if they arent there it will take overall\n"+
"-------------------------------------------------\n"+
"For those wondering why the kd with a weapon doesnt match the webclient,\nthe webclient takes kills with a weapon and deaths to that weapon and this bot takes kills with weapon and deaths while weapon is held")
elif(message == "leaderboard"):
botmessage = str("!leaderboard is a leaderboard that can be filtered, also for the lazy between us leaderboard can be subsituted by lb, rank, ranking \n"
+"currently the leaderboard can only be filtered by kills, deaths, max_distance, total_distance with a specified weapon \n" +
"Example: \n!lb kills, kraber \n!lb <filter>, <weaponname> \nA weapon doesnt need to be specified")
botmessage = str("!leaderboard is a leaderboard that can be filtered, also for the lazy between us leaderboard can be subsituted by lb, rank, ranking, board \n"
+"currently the leaderboard can only be filtered by kills, deaths, maxd, totald, kd and avgd with a specified weapon \n" +
"Example: \n!lb kills, kraber, fvnkhead's 3v3 \n!lb <filter>, <weaponname>, <servername> \nA weapon or server doesnt need to be specified\n"+
"------------------------\n"+
"maxd = max distance, avgd = average distance, kd = kill/death ratio and totald = total distance"
)
elif(message == "slashcommands"):
botmessage = str("To do a slash command, hit the / key and navigate to the sonar icon after doing this you will see all the commands.\nThese commands take the same input as the normal !commands")
else:
botmessage = "Cant help you with this"
+20
View File
@@ -0,0 +1,20 @@
import discord
from discord.ext import commands
class Invite(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Invite.py is ready")
@commands.command()
async def invite(self, ctx):
link = "https://discord.com/api/oauth2/authorize?client_id=1100115547515011182&permissions=414464862272&scope=bot"
await ctx.send("I'm already in " + str(len(self.client.guilds)) + " servers!\n" + "Invite me now using:\n " + link)
async def setup(client):
await client.add_cog(Invite(client))
+187 -82
View File
@@ -11,106 +11,211 @@ class Leaderboard(commands.Cog):
print("Leaderboard.py is ready")
@commands.command(aliases = ["lb", "board", "ranking", "rank"])
async def leaderboard(self, ctx, message, weapon=""):
message = message.lower()
weaponid = ""
botmessage = "Leaderboard of " + message + "\n"
if(weapon != ""):
weaponid = self.getweaponid(weapon)
message = message[:-1]
if(message != "deaths"):
inbetween = " with "
async def leaderboard(self, ctx, *message):
boards = ["kd", "avgd", "maxd", "totald","deaths", "kills"]
error = False
board = ""
servers = []
server = ""
weaponid= ""
weaponname= ""
if(message == ()):
error = True
botmessage = "No leaderboard option selected, choose from:\n"
for i in boards:
botmessage = botmessage + i + "\n"
await ctx.send(botmessage)
for i in message:
item = i.replace(",", "")
if(item.lower() not in boards):
function_dict = self.message_handler(item)
if(function_dict['weapon'] != None):
weaponname = function_dict["weapon"][1]
weaponid= function_dict['weapon'][0]
if(function_dict['server'] != None):
servers.append(function_dict['server'])
else:
inbetween = " to "
botmessage = "Leaderboard of " + message + inbetween + weapon + "\n"
board = item
if(str(message) not in ["kills", "deaths", "max_distance", "total_distance"]):
await ctx.send('```This filter doesnt exist```')
print(message)
if(board == "" and error == False):
error = True
botmessage = "No leaderboard option selected, choose from:\n"
for i in boards:
botmessage = botmessage + i + "\n"
await ctx.send(botmessage)
if(len(servers) != 0):
if(len(servers) > 1):
for i in servers:
if(i in " ".join(message)):
server = i
break
else:
server = servers[0]
payload = {"weapon": weaponid}
botmessage = self.getleaderboard(weaponid=weaponid, weaponname=weaponname, server=server, board=board)
await ctx.send(f'```{botmessage}```')
def message_handler(self, message):
weapon = False
server = False
return_message = {"weapon": None, "server": None}
weaponid, weaponname = self.getweaponid(message)
if(weaponid != ""):
weapon = True
servername = self.getserver(message)
if(servername != ""):
server = True
if(server):
return_message["server"] = servername
if(weapon):
return_message["weapon"] = [weaponid, weaponname]
return return_message
def getweaponid(self, weaponname):
weapons ={
"execution": "human_execution",
"car": "mp_weapon_car",
"charge rifle": "mp_weapon_defender",
"double take": "mp_weapon_doubletake",
"epg": "mp_weapon_epg",
"volt": "mp_weapon_hemlok_smg",
"lstar": "mp_weapon_lstar",
"r97": "mp_weapon_r97",
"r-201": "mp_weapon_rspn101",
"smart pistol": "mp_weapon_smart_pistol",
"kraber": "mp_weapon_sniper",
"flatline": "mp_weapon_vinson",
"re-45 auto": "mp_weapon_autopistol",
"alternator": "mp_weapon_alternator_smg",
"frag grenade": "mp_weapon_frag_grenade",
"g2": "mp_weapon_g2",
"spitfire": "mp_weapon_lmg",
"smr": "mp_weapon_smr",
"softball": "mp_weapon_softball",
"firestar": "mp_weapon_thermite_grenade",
"melee": "melee_pilot_emptyhanded",
"masstiff": "mp_weapon_mastiff",
"mgl": "mp_weapon_mgl",
"r-101": "mp_weapon_rspn101_og",
"wingman": "mp_weapon_wingman",
"invalid": "invalid",
"thunderbolt": "mp_weapon_arc_launcher",
"dmr": "mp_weapon_dmr",
"electric smoke": "mp_weapon_grenade_electric_smoke",
"cold war": "mp_weapon_pulse_lmg",
"satchel": "mp_weapon_satchel",
"eva-8 auto": "mp_weapon_shotgun",
"mozambique": "mp_weapon_shotgun_pistol",
"wingman elite": "mp_weapon_wingman_n",
"gravity star": "mp_weapon_grenade_gravity",
"pulse blade": "mp_weapon_grenade_sonar",
"archer": "mp_weapon_rocket_launcher",
"outOfBounds": "outOfBounds",
"mind crime": "mind_crime",
"devotion": "mp_weapon_esaw",
"fall": "fall",
"p2016": "mp_weapon_semipistol",
"arc grenade": "mp_weapon_grenade_emp",
"hemlok": "mp_weapon_hemlok",
"phase shift": "phase_shift"
}
weaponid = ""
for weapon in weapons:
if(weaponname.lower() in weapon.lower()):
weaponid = weapons[weapon]
weaponname = weapon
break
return weaponid, weaponname
def getserver(self, snippet):
server = ""
response = requests.get('https://tone.sleepycat.date/v2/client/servers').json()
servers = response.keys()
for i in servers:
if(snippet.lower() in i.lower()):
server = i
break
return server
def getleaderboard(self, board, weaponid="", weaponname="", server=""):
easyfilter = False
hardfilter = False
payload = {"weapon": weaponid, "server": server}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
players = response.keys()
top10 = []
if(board.lower() in ["kills", "deaths", "maxd", "totald"]):
if(board.lower() == "totald"):
board = "total_distance"
if(board.lower() == "maxd"):
board = "max_distance"
easyfilter = True
else:
hardfilter = True
top10 = {}
while(len(top10)<10):
current = 0
name = ""
for p in players:
stats = response[p]
checked = stats[str(message)]
if(checked > current and str(stats["username"] +": " + str(stats[str(message)])) not in top10):
if(easyfilter):
checked = stats[str(board)]
if(hardfilter):
if(board.lower() == "kd"):
if (stats['deaths'] == 0):
deaths = 1
else:
deaths = stats['deaths']
checked = round(stats["kills"] / deaths, 2)
if(board.lower() == "avgd"):
if(stats["kills"] == 0):
kills = 1
else:
kills = stats["kills"]
checked = round(stats["total_distance"] / kills, 2)
#print(checked, ", ", current )
if(checked >= current and stats["username"] not in top10.keys()):
#print(checked, ", ", current)
current = checked
name = stats['username']
top10.append(name+ ": " + str(current))
top10[name] = current
if(board.lower() == "deaths"):
inbetween = "to"
else:
inbetween = "with"
if(server == ""):
server = "all servers"
if(weaponname == ""):
weaponname = "any weapon"
botmessage = str(f"Leaderboard of {board} {inbetween} {weaponname} for {server}\n-------------------------------\n")
counter = 1
for i in top10:
botmessage = botmessage + str(str(counter) + " - " + i + "\n")
for i, j in top10.items():
if(hardfilter):
stat = str("{:0.2f}".format(j))
if(easyfilter):
stat = str(j)
botmessage = botmessage + str(f"{str(counter):<2}"+ " - " + f"{i :<15}" + " : "+ f"{stat:<8}" + "\n")
counter= counter+1
await ctx.send(f'```{botmessage}```')
def getweaponid(self, weaponname):
response = requests.get('https://tone.sleepycat.date/v2/client/weapons').json()
r = response.keys()
weapon_dict = {'execution': 'human_execution',
'mp_weapon_car': 'car',
'mp_weapon_defender': 'charge_rifle',
'mp_weapon_doubletake': 'double_take',
'mp_weapon_epg': 'epg',
'mp_weapon_hemlok_smg': 'volt',
'mp_weapon_lstar': 'lstar',
'mp_weapon_r97':'r97',
'mp_weapon_rspn101': 'r-201',
'mp_weapon_smart_pistol': 'smart_pistol',
'mp_weapon_sniper': 'kraber',
'mp_weapon_vinson': 'flatline',
'mp_weapon_autopistol': 're-45_auto',
'mp_weapon_alternator_smg': 'alternator',
'mp_weapon_frag_grenade': 'frag_grenade',
'mp_weapon_g2': 'g2',
'mp_weapon_lmg': 'spitfire',
'mp_weapon_smr': 'smr',
'mp_weapon_softball': 'softball',
'mp_weapon_thermite_grenade': 'firestar',
'pilot_emptyhanded': 'melee',
'mp_weapon_mastiff': 'masstiff',
'mp_weapon_mgl': 'mgl',
'mp_weapon_rspn101_og': 'r-101',
'mp_weapon_wingman': 'wingman',
'invalid': 'invalid',
'mp_weapon_arc_launcher': 'thunderbolt',
'mp_weapon_dmr': 'dmr',
'mp_weapon_grenade_electric_smoke': 'electric_smoke',
'mp_weapon_pulse_lmg': 'cold_war',
'mp_weapon_satchel': 'satchel',
'mp_weapon_shotgun': 'eva-8_auto',
'mp_weapon_shotgun_pistol': 'mozambique',
'mp_weapon_wingman_n': 'wingman_elite',
'mp_weapon_grenade_gravity': 'gravity_star',
'mp_weapon_grenade_sonar': 'pulse_blade',
'mp_weapon_rocket_launcher': 'archer',
'outOfBounds': 'outOfBounds',
'mind_crime': 'mind_crime',
'mp_weapon_esaw': 'devotion',
'fall': 'fall',
'mp_weapon_semipistol': 'p2016',
'mp_weapon_grenade_emp': 'arc_grenade',
'mp_weapon_hemlok': 'hemlok',
'melee_pilot_emptyhanded': 'melee',
'phase_shift': 'phase_shift'
}
weaponid = ""
for i in r:
if(i in weapon_dict.keys()):
if (weaponname.lower() == weapon_dict[i]):
weaponid = i
break
return weaponid
return botmessage
async def setup(client):
await client.add_cog(Leaderboard(client))
+7
View File
@@ -11,6 +11,7 @@ class Roll(commands.Cog):
print("roll.py is ready")
@commands.command()
@commands.cooldown(1, 600, commands.BucketType.user)
async def roll(self, ctx):
rolled = random.randint(1,100)
rating = ""
@@ -38,6 +39,12 @@ class Roll(commands.Cog):
await ctx.send(message)
@roll.error
async def on_command_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
time = round(error.retry_after/60)
message = f"This command is on cooldown, the cooldown ends in {time} minutes"
await ctx.send(message)
async def setup(client):
await client.add_cog(Roll(client))
+163 -80
View File
@@ -11,38 +11,85 @@ class Stats(commands.Cog):
async def on_ready(self):
print("stats.py is ready")
@commands.command()
async def stats(self, ctx, message="any player", message2="any weapon"):
if(message != "any player"):
weaponid = ""
if(message2 != "any weapon"):
message = message[:-1]
weaponid = self.getweaponid(message2)
playerid = ""
playerid = self.getplayerid(message);
if (playerid != ""):
payload = {'player': playerid, 'weapon': weaponid}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
killstats = response[playerid]
botmessage = str("Playername: " + killstats['username'] + '\n' + "Kills : " + str(killstats['kills']) + '\n' )
@commands.command(aliases=["compare"])
async def stats(self, ctx, *message):
error = False
players = []
servers = []
server = ""
weaponid= ""
weaponname= ""
if(weaponid != ""):
deaths=killstats['deaths_while_equipped']
if(deaths == 0):
deaths = 1;
botmessage += str("Deaths : " + str(killstats['deaths_while_equipped'])) + '\n' + str("Weapon : " + message2) + '\n' + str(str("weapon KD : " + str("{:0.2f}".format(killstats['kills']/deaths))))
if(message == ()):
await ctx.send("```No player given```")
error = True
for i in message:
item = i.replace(",", "")
function_dict = self.message_handler(item)
if(function_dict['player'] != None):
players.append(function_dict['player'])
if(function_dict['weapon'] != None):
weaponname = function_dict["weapon"][1]
weaponid= function_dict['weapon'][0]
if(function_dict['server'] != None):
servers.append(function_dict['server'])
if(len(servers) != 0):
if(len(servers) > 1):
for i in servers:
if(i in " ".join(message)):
server = i
break
else:
deaths=killstats['deaths']
if(deaths == 0):
deaths = 1;
botmessage = botmessage + str("Deaths : " + str(killstats['deaths'])) + '\n' + str("KD : " + str("{:0.2f}".format(killstats['kills']/deaths)))
server = servers[0]
if(len(players) == 0 and error == False):
error = True
await ctx.send("```No existing player found, check if the name is correct or has changed```")
list_of_stats = []
for i in players:
stats = self.getstats(playerid=i,weaponid=weaponid, weaponname=weaponname, server=server)
list_of_stats.append(stats)
if ("".join(list_of_stats) != ""):
if(server != ""):
botmessage = str("Stats for " + server + "\n" + "---------------------" + "\n")
else:
botmessage = "This player doesnt exist"
else:
botmessage = "No name given"
botmessage = str("Stats for all servers\n" + "---------------------" + "\n")
divider = str("\n --------------------- \n")
botmessage = botmessage + divider.join(list_of_stats)
await ctx.send(f'```{botmessage}```')
def message_handler(self, message):
player = False
weapon = False
server = False
return_message = {"player": None, "weapon": None, "server": None}
playerid = self.getplayerid(message)
if(playerid != ""):
player = True
weaponid, weaponname = self.getweaponid(message)
if(weaponid != ""):
weapon = True
servername = self.getserver(message)
if(servername != ""):
server = True
if(server):
return_message["server"] = servername
if(player):
return_message["player"] = playerid
if(weapon):
return_message["weapon"] = [weaponid, weaponname]
return return_message
def getplayerid(self, playername):
playerid = ""
payload = str("username=") + playername
@@ -52,64 +99,100 @@ class Stats(commands.Cog):
return str(playerid)
def getweaponid(self, weaponname):
response = requests.get('https://tone.sleepycat.date/v2/client/weapons').json()
r = response.keys()
weapon_dict = {'execution': 'human_execution',
'mp_weapon_car': 'car',
'mp_weapon_defender': 'charge_rifle',
'mp_weapon_doubletake': 'double_take',
'mp_weapon_epg': 'epg',
'mp_weapon_hemlok_smg': 'volt',
'mp_weapon_lstar': 'lstar',
'mp_weapon_r97':'r97',
'mp_weapon_rspn101': 'r-201',
'mp_weapon_smart_pistol': 'smart_pistol',
'mp_weapon_sniper': 'kraber',
'mp_weapon_vinson': 'flatline',
'mp_weapon_autopistol': 're-45_auto',
'mp_weapon_alternator_smg': 'alternator',
'mp_weapon_frag_grenade': 'frag_grenade',
'mp_weapon_g2': 'g2',
'mp_weapon_lmg': 'spitfire',
'mp_weapon_smr': 'smr',
'mp_weapon_softball': 'softball',
'mp_weapon_thermite_grenade': 'firestar',
'pilot_emptyhanded': 'melee',
'mp_weapon_mastiff': 'masstiff',
'mp_weapon_mgl': 'mgl',
'mp_weapon_rspn101_og': 'r-101',
'mp_weapon_wingman': 'wingman',
'invalid': 'invalid',
'mp_weapon_arc_launcher': 'thunderbolt',
'mp_weapon_dmr': 'dmr',
'mp_weapon_grenade_electric_smoke': 'electric_smoke',
'mp_weapon_pulse_lmg': 'cold_war',
'mp_weapon_satchel': 'satchel',
'mp_weapon_shotgun': 'eva-8_auto',
'mp_weapon_shotgun_pistol': 'mozambique',
'mp_weapon_wingman_n': 'wingman_elite',
'mp_weapon_grenade_gravity': 'gravity_star',
'mp_weapon_grenade_sonar': 'pulse_blade',
'mp_weapon_rocket_launcher': 'archer',
'outOfBounds': 'outOfBounds',
'mind_crime': 'mind_crime',
'mp_weapon_esaw': 'devotion',
'fall': 'fall',
'mp_weapon_semipistol': 'p2016',
'mp_weapon_grenade_emp': 'arc_grenade',
'mp_weapon_hemlok': 'hemlok',
'melee_pilot_emptyhanded': 'melee',
'phase_shift': 'phase_shift'
weapons ={
"execution": "human_execution",
"car": "mp_weapon_car",
"charge rifle": "mp_weapon_defender",
"double take": "mp_weapon_doubletake",
"epg": "mp_weapon_epg",
"volt": "mp_weapon_hemlok_smg",
"lstar": "mp_weapon_lstar",
"r97": "mp_weapon_r97",
"r-201": "mp_weapon_rspn101",
"smart pistol": "mp_weapon_smart_pistol",
"kraber": "mp_weapon_sniper",
"flatline": "mp_weapon_vinson",
"re-45 auto": "mp_weapon_autopistol",
"alternator": "mp_weapon_alternator_smg",
"frag grenade": "mp_weapon_frag_grenade",
"g2": "mp_weapon_g2",
"spitfire": "mp_weapon_lmg",
"smr": "mp_weapon_smr",
"softball": "mp_weapon_softball",
"firestar": "mp_weapon_thermite_grenade",
"melee": "melee_pilot_emptyhanded",
"masstiff": "mp_weapon_mastiff",
"mgl": "mp_weapon_mgl",
"r-101": "mp_weapon_rspn101_og",
"wingman": "mp_weapon_wingman",
"invalid": "invalid",
"thunderbolt": "mp_weapon_arc_launcher",
"dmr": "mp_weapon_dmr",
"electric smoke": "mp_weapon_grenade_electric_smoke",
"cold war": "mp_weapon_pulse_lmg",
"satchel": "mp_weapon_satchel",
"eva-8 auto": "mp_weapon_shotgun",
"mozambique": "mp_weapon_shotgun_pistol",
"wingman elite": "mp_weapon_wingman_n",
"gravity star": "mp_weapon_grenade_gravity",
"pulse blade": "mp_weapon_grenade_sonar",
"archer": "mp_weapon_rocket_launcher",
"outOfBounds": "outOfBounds",
"mind crime": "mind_crime",
"devotion": "mp_weapon_esaw",
"fall": "fall",
"p2016": "mp_weapon_semipistol",
"arc grenade": "mp_weapon_grenade_emp",
"hemlok": "mp_weapon_hemlok",
"phase shift": "phase_shift"
}
weaponid = ""
for i in r:
if(i in weapon_dict.keys()):
if (weaponname.lower() == weapon_dict[i]):
weaponid = i
for weapon in weapons:
if(weaponname.lower() in weapon.lower()):
weaponid = weapons[weapon]
weaponname = weapon
break
return weaponid
return weaponid, weaponname
def getserver(self, snippet):
server = ""
response = requests.get('https://tone.sleepycat.date/v2/client/servers').json()
servers = response.keys()
for i in servers:
if(snippet.lower() in i.lower()):
server = i
break
return server
def getstats(self, playerid, weaponid = "", weaponname = "", server = ""):
payload = {'player': playerid, 'weapon': weaponid, 'server': server}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
if(response == {}):
errorresponse = requests.get("https://northstar.tf/accounts/get_username", params={"uid": playerid}).json()
if(errorresponse['matches'] != None):
playername = errorresponse['matches'][0]
return str("No stats found for player: " + playername)
killstats = response[str(playerid)]
botmessage = str("Playername: " + killstats['username'] + '\n' + "Kills : " + str(killstats['kills']) + '\n' )
if(weaponid != ""):
deaths=killstats['deaths_while_equipped']
if(deaths == 0):
deaths = 1;
botmessage += str("Deaths : " + str(killstats['deaths_while_equipped'])) + '\n' + str("Weapon : " + weaponname) + '\n' + str(str("weapon KD : " + str("{:0.2f}".format(killstats['kills']/deaths))))
else:
deaths=killstats['deaths']
if(deaths == 0):
deaths = 1;
botmessage = botmessage + str("Deaths : " + str(killstats['deaths'])) + '\n' + str("KD : " + str("{:0.2f}".format(killstats['kills']/deaths)))
return botmessage
async def setup(client):
await client.add_cog(Stats(client))
+36
View File
@@ -0,0 +1,36 @@
import discord
from discord.ext import commands
from discord import app_commands
class SlashChangelog(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashChanglog.py is ready")
@app_commands.command(name="changelog", description="Gives all the changes and updates to new or old commands")
async def changelog(self, interaction: discord.Interaction):
botmessage = str(
"Welcome to V1.1 of Sonar, we have lots to discuss because alot has changed or got added.\n\n"+
"-change 1, !stats and !compare arent 2 different functions anymore but became 1 function,\n"+
"so now you can do !stats <playername>, <playername>, <weapon>, or for those who like to write !compare this still works aswell.\n\n"+
"-change 2, !stats, !lb (!leaderboard) got <server> filters so now its possible to see your standing in a server.\n\n"
"-change 3, All currently existing commands did get an overhaul to make them less restrictive to people, so you no longer need to write wingman_elite,\n"+
"you can now do wingman elite or elite to get the wingman elite as filter, servers do have the same principle\n\n"+
"-change 4, clearer error message\n\n"+
"-change 5, All currently existing commands did get a slash command counterpart\n\n"+
"Thanks for reading and goodluck increasing those stats"
)
await interaction.response.send_message(f"```{botmessage}```")
async def setup(client):
await client.add_cog(SlashChangelog(client))
+57
View File
@@ -0,0 +1,57 @@
import discord
from discord.ext import commands
from discord import app_commands
class SlashHelp(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashHelp.py is ready")
@app_commands.command(name="help", description= "Gives information about the commands in this bot")
async def help(self, interaction: discord.Interaction, message:str ="all"):
botmessage = ""
if(message == "all"):
botmessage = str("To get further information about a command do: \n!help <command> \n------------------- \n" +
"The commands you can get information on are: \n" +
"changelog : Gives all the information about the changes and updates.\n"
"roll : Rolls a number between 1 and 100. \n" +
"ping : Shows latency. \n" +
"stats : Shows stats collected by ToneAPI. \n" +
"leaderboard : Shows a leaderboard of stats. \n"+
"slashcommands: This explains what slash commands are, if you used slash commands before this isnt usefull\n"
"------------------- \n"
"if this help command doesnt help you or you have suggestions for future commands, ping or dm me @lars#1029")
elif(message == "changelog"):
botmessage = str("!changelogs is a command that gives you all the recent changes and updates")
elif(message == "roll"):
botmessage = str("!roll is a command that rolls a number between 1 and 100, with a rating")
elif(message == "ping"):
botmessage = str("!ping gives the latency between you and the bot")
elif(message == "stats"):
botmessage = str("!stats takes playername(s), Optional: weaponname, servername\n"+
"Example: \n!stats iilars, kraber, fvnkhead's 3v3 \n!stats <playername>, <weaponname>, <servername> \nA weapon or server doesnt need to be specified, because if they arent there it will take overall\n"+
"-------------------------------------------------\n"+
"For those wondering why the kd with a weapon doesnt match the webclient,\nthe webclient takes kills with a weapon and deaths to that weapon and this bot takes kills with weapon and deaths while weapon is held")
elif(message == "leaderboard"):
botmessage = str("!leaderboard is a leaderboard that can be filtered, also for the lazy between us leaderboard can be subsituted by lb, rank, ranking, board \n"
+"currently the leaderboard can only be filtered by kills, deaths, maxd, totald, kd and avgd with a specified weapon \n" +
"Example: \n!lb kills, kraber, fvnkhead's 3v3 \n!lb <filter>, <weaponname>, <servername> \nA weapon or server doesnt need to be specified\n"+
"------------------------\n"+
"maxd = max distance, avgd = average distance, kd = kill/death ratio and totald = total distance"
)
elif(message == "slashcommands"):
botmessage = str("To do a slash command, hit the / key and navigate to the sonar icon after doing this you will see all the commands.\nThese commands take the same input as the normal !commands")
else:
botmessage = "Cant help you with this"
await interaction.response.send_message(f"```{botmessage}```")
async def setup(client):
await client.add_cog(SlashHelp(client))
+19
View File
@@ -0,0 +1,19 @@
import discord
from discord.ext import commands
from discord import app_commands
class SlashInvite(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashInvite.py is ready")
@app_commands.command(name="invite", description="Tells you in how many servers sonar is active and gives an invite link with it")
async def invite(self, interaction: discord.Interaction):
link = "https://discord.com/api/oauth2/authorize?client_id=1100115547515011182&permissions=414464862272&scope=bot"
await interaction.response.send_message("I'm already in " + str(len(self.client.guilds)) + " servers!\n" + "Invite me now using:\n " + link)
async def setup(client):
await client.add_cog(SlashInvite(client))
+201
View File
@@ -0,0 +1,201 @@
import discord
from discord.ext import commands
from discord import app_commands
import requests
class SlashLeaderboard(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashLeaderboard.py is ready")
@app_commands.command(name="leaderboard", description="Gives the leaderboard of selected filter, possible to be narrowed down on weapon and server")
@app_commands.describe(board = "The filter that decides the stat the leaderboard gets ordered at",weapon = "Ingame Weaponname", servername = "A Tone supported server")
@app_commands.rename(board = "filter", servername = "server")
async def leaderboard(self, interaction: discord.Interaction, board: str, weapon : str = "", servername : str = ""):
boards = ["kd", "avgd", "maxd", "totald","deaths", "kills"]
server = ""
weaponid= ""
weaponname= ""
if(weapon != ""):
weaponid, weaponname = self.getweaponid(weapon)
if(servername != ""):
server = self.getserver(servername)
if(board in boards):
botmessage = self.getleaderboard(weaponid=weaponid, weaponname=weaponname, server=server, board=board)
else:
botmessage = "You gave a none existing filter"
await interaction.response.send_message(f'```{botmessage}```')
def getweaponid(self, weaponname):
weapons ={
"execution": "human_execution",
"car": "mp_weapon_car",
"charge rifle": "mp_weapon_defender",
"double take": "mp_weapon_doubletake",
"epg": "mp_weapon_epg",
"volt": "mp_weapon_hemlok_smg",
"lstar": "mp_weapon_lstar",
"r97": "mp_weapon_r97",
"r-201": "mp_weapon_rspn101",
"smart pistol": "mp_weapon_smart_pistol",
"kraber": "mp_weapon_sniper",
"flatline": "mp_weapon_vinson",
"re-45 auto": "mp_weapon_autopistol",
"alternator": "mp_weapon_alternator_smg",
"frag grenade": "mp_weapon_frag_grenade",
"g2": "mp_weapon_g2",
"spitfire": "mp_weapon_lmg",
"smr": "mp_weapon_smr",
"softball": "mp_weapon_softball",
"firestar": "mp_weapon_thermite_grenade",
"melee": "melee_pilot_emptyhanded",
"masstiff": "mp_weapon_mastiff",
"mgl": "mp_weapon_mgl",
"r-101": "mp_weapon_rspn101_og",
"wingman": "mp_weapon_wingman",
"invalid": "invalid",
"thunderbolt": "mp_weapon_arc_launcher",
"dmr": "mp_weapon_dmr",
"electric smoke": "mp_weapon_grenade_electric_smoke",
"cold war": "mp_weapon_pulse_lmg",
"satchel": "mp_weapon_satchel",
"eva-8 auto": "mp_weapon_shotgun",
"mozambique": "mp_weapon_shotgun_pistol",
"wingman elite": "mp_weapon_wingman_n",
"gravity star": "mp_weapon_grenade_gravity",
"pulse blade": "mp_weapon_grenade_sonar",
"archer": "mp_weapon_rocket_launcher",
"outOfBounds": "outOfBounds",
"mind crime": "mind_crime",
"devotion": "mp_weapon_esaw",
"fall": "fall",
"p2016": "mp_weapon_semipistol",
"arc grenade": "mp_weapon_grenade_emp",
"hemlok": "mp_weapon_hemlok",
"phase shift": "phase_shift"
}
weaponid = ""
for weapon in weapons:
if(weaponname.lower() in weapon.lower()):
weaponid = weapons[weapon]
weaponname = weapon
break
return weaponid, weaponname
def getserver(self, snippet):
server = ""
response = requests.get('https://tone.sleepycat.date/v2/client/servers').json()
servers = response.keys()
for i in servers:
if(snippet.lower() in i.lower()):
server = i
break
return server
def getleaderboard(self, board, weaponid="", weaponname="", server=""):
easyfilter = False
hardfilter = False
payload = {"weapon": weaponid, "server": server}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
players = response.keys()
if(board.lower() in ["kills", "deaths", "maxd", "totald"]):
if(board.lower() == "totald"):
board = "total_distance"
if(board.lower() == "maxd"):
board = "max_distance"
easyfilter = True
else:
hardfilter = True
top10 = {}
while(len(top10)<10):
current = 0
name = ""
for p in players:
stats = response[p]
if(easyfilter):
checked = stats[str(board)]
if(hardfilter):
if(board.lower() == "kd"):
if (stats['deaths'] == 0):
deaths = 1
else:
deaths = stats['deaths']
checked = round(stats["kills"] / deaths, 2)
if(board.lower() == "avgd"):
if(stats["kills"] == 0):
kills = 1
else:
kills = stats["kills"]
checked = round(stats["total_distance"] / kills, 2)
#print(checked, ", ", current )
if(checked >= current and stats["username"] not in top10.keys()):
#print(checked, ", ", current)
current = checked
name = stats['username']
top10[name] = current
if(board.lower() == "deaths"):
inbetween = "to"
else:
inbetween = "with"
if(server == ""):
server = "all servers"
if(weaponname == ""):
weaponname = "any weapon"
botmessage = str(f"Leaderboard of {board} {inbetween} {weaponname} for {server}\n-------------------------------\n")
counter = 1
for i, j in top10.items():
if(hardfilter):
stat = str("{:0.2f}".format(j))
if(easyfilter):
stat = str(j)
botmessage = botmessage + str(f"{str(counter):<2}"+ " - " + f"{i :<15}" + " : "+ f"{stat:<8}" + "\n")
counter= counter+1
return botmessage
@leaderboard.autocomplete("weapon")
async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'masstiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift']
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
@leaderboard.autocomplete("servername")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
servers = requests.get("https://tone.sleepycat.date/v2/client/servers").json()
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
@leaderboard.autocomplete("board")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
boards = ["kd", "avgd", "maxd", "totald","deaths", "kills"]
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
async def setup(client):
await client.add_cog(SlashLeaderboard(client))
+20
View File
@@ -0,0 +1,20 @@
import discord
from discord.ext import commands
from discord import app_commands
class SlashPing(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashPing.py is ready")
@app_commands.command(name="ping", description="Gives the bot latency in ms.")
async def slashping(self, interaction: discord.Interaction):
bot_latency = round(self.client.latency * 1000)
await interaction.response.send_message(f"pong! {bot_latency}ms.")
async def setup(client):
await client.add_cog(SlashPing(client))
+52
View File
@@ -0,0 +1,52 @@
import discord
from discord import app_commands
from discord.ext import commands
import random
class SlashRoll(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashRoll.py is ready")
@app_commands.command(name="roll", description="Rolls a number between 1 and 100 with a rating")
@app_commands.checks.cooldown(1, 600)
async def slashroll(self, interaction: discord.Interaction):
rolled = random.randint(1,100)
rating = ""
if(rolled == 100):
rating = "What a chad"
elif(rolled < 100 and rolled > 90):
rating = "Almost"
elif(rolled <= 90 and rolled > 80):
rating = "Good"
elif(rolled <= 80 and rolled > 69):
rating = "Alright"
elif(rolled == 69):
rating = "Nice"
elif(rolled < 69 and rolled > 50):
rating = "Decent"
elif(rolled <= 50 and rolled > 25):
rating = "Meh"
elif(rolled <= 25 and rolled > 1):
rating = "Bad"
elif(rolled == 1):
rating = "LOL"
message = "You rolled " + str(rolled) + ", " + rating
await interaction.response.send_message(message)
@slashroll.error
async def on_command_error(self, interaction: discord.Interaction, error : app_commands.AppCommandError):
if isinstance(error, app_commands.CommandOnCooldown):
time = round(error.retry_after/60)
message = f"This command is on cooldown, the cooldown ends in {time} minutes"
await interaction.response.send_message(message)
async def setup(client):
await client.add_cog(SlashRoll(client))
+184
View File
@@ -0,0 +1,184 @@
import discord
from discord.ext import commands
from discord import app_commands
import requests
class SlashStats(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("SlashStats.py is ready")
@app_commands.command(name="stats", description="Gives the stats of the selected player/players filtered by weapon and server, if given")
@app_commands.describe(playernames = "Ingame name of the player or players", weapon = "Ingame Weaponname", servername = "A Tone supported server")
@app_commands.rename(playernames = "player", servername = "server")
async def stats(self, interaction: discord.Interaction, playernames : str, weapon : str = "", servername : str = ""):
error = False
playernames = playernames.replace(",", "")
playernames = playernames.split(" ")
players = []
server = ""
weaponid= ""
weaponname= ""
print(playernames)
for i in playernames:
playerid = self.getplayerid(i)
if(playerid != ""):
players.append(playerid)
if(weapon != ""):
weaponid, weaponname = self.getweaponid(weapon)
if(servername != ""):
server = self.getserver(servername)
if(len(players) == 0 and error == False):
error = True
await interaction.response.send_message("```No existing player found, check if the name is correct or has changed```")
list_of_stats = []
for i in players:
stats = self.getstats(playerid=i,weaponid=weaponid, weaponname=weaponname, server=server)
list_of_stats.append(stats)
if ("".join(list_of_stats) != ""):
if(server != ""):
botmessage = str("Stats for " + server + "\n" + "---------------------" + "\n")
else:
botmessage = str("Stats for all servers\n" + "---------------------" + "\n")
divider = str("\n --------------------- \n")
botmessage = botmessage + divider.join(list_of_stats)
await interaction.response.send_message(f'```{botmessage}```')
def getplayerid(self, playername):
playerid = ""
payload = str("username=") + playername
response = requests.get('https://northstar.tf/accounts/lookup_uid', params=payload).json()
if (response['matches'] != None):
playerid = response['matches'][0]
return str(playerid)
def getweaponid(self, weaponname):
weapons ={
"execution": "human_execution",
"car": "mp_weapon_car",
"charge rifle": "mp_weapon_defender",
"double take": "mp_weapon_doubletake",
"epg": "mp_weapon_epg",
"volt": "mp_weapon_hemlok_smg",
"lstar": "mp_weapon_lstar",
"r97": "mp_weapon_r97",
"r-201": "mp_weapon_rspn101",
"smart pistol": "mp_weapon_smart_pistol",
"kraber": "mp_weapon_sniper",
"flatline": "mp_weapon_vinson",
"re-45 auto": "mp_weapon_autopistol",
"alternator": "mp_weapon_alternator_smg",
"frag grenade": "mp_weapon_frag_grenade",
"g2": "mp_weapon_g2",
"spitfire": "mp_weapon_lmg",
"smr": "mp_weapon_smr",
"softball": "mp_weapon_softball",
"firestar": "mp_weapon_thermite_grenade",
"melee": "melee_pilot_emptyhanded",
"masstiff": "mp_weapon_mastiff",
"mgl": "mp_weapon_mgl",
"r-101": "mp_weapon_rspn101_og",
"wingman": "mp_weapon_wingman",
"invalid": "invalid",
"thunderbolt": "mp_weapon_arc_launcher",
"dmr": "mp_weapon_dmr",
"electric smoke": "mp_weapon_grenade_electric_smoke",
"cold war": "mp_weapon_pulse_lmg",
"satchel": "mp_weapon_satchel",
"eva-8 auto": "mp_weapon_shotgun",
"mozambique": "mp_weapon_shotgun_pistol",
"wingman elite": "mp_weapon_wingman_n",
"gravity star": "mp_weapon_grenade_gravity",
"pulse blade": "mp_weapon_grenade_sonar",
"archer": "mp_weapon_rocket_launcher",
"outOfBounds": "outOfBounds",
"mind crime": "mind_crime",
"devotion": "mp_weapon_esaw",
"fall": "fall",
"p2016": "mp_weapon_semipistol",
"arc grenade": "mp_weapon_grenade_emp",
"hemlok": "mp_weapon_hemlok",
"phase shift": "phase_shift"
}
weaponid = ""
for weapon in weapons:
if(weaponname.lower() in weapon.lower()):
weaponid = weapons[weapon]
weaponname = weapon
break
if(weaponid == ""):
weaponname = ""
return weaponid, weaponname
def getserver(self, snippet):
server = ""
response = requests.get('https://tone.sleepycat.date/v2/client/servers').json()
servers = response.keys()
for i in servers:
if(snippet.lower() in i.lower()):
server = i
break
return server
def getstats(self, playerid, weaponid = "", weaponname = "", server = ""):
payload = {'player': playerid, 'weapon': weaponid, 'server': server}
response = requests.get('https://tone.sleepycat.date/v2/client/players', params=payload).json()
if(response == {}):
errorresponse = requests.get("https://northstar.tf/accounts/get_username", params={"uid": playerid}).json()
if(errorresponse['matches'] != None):
playername = errorresponse['matches'][0]
return str("No stats found for player: " + playername)
killstats = response[str(playerid)]
botmessage = str("Playername: " + killstats['username'] + '\n' + "Kills : " + str(killstats['kills']) + '\n' )
if(weaponid != ""):
deaths=killstats['deaths_while_equipped']
if(deaths == 0):
deaths = 1;
botmessage += str("Deaths : " + str(killstats['deaths_while_equipped'])) + '\n' + str("Weapon : " + weaponname) + '\n' + str(str("weapon KD : " + str("{:0.2f}".format(killstats['kills']/deaths))))
else:
deaths=killstats['deaths']
if(deaths == 0):
deaths = 1;
botmessage = botmessage + str("Deaths : " + str(killstats['deaths'])) + '\n' + str("KD : " + str("{:0.2f}".format(killstats['kills']/deaths)))
return botmessage
@stats.autocomplete("weapon")
async def autocomplete_weapon(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
weaponlist = ['execution', 'car', 'charge rifle', 'double take', 'epg', 'volt', 'lstar', 'r97', 'r-201', 'smart pistol', 'kraber', 'flatline', 're-45 auto', 'alternator', 'frag grenade', 'g2', 'spitfire', 'smr', 'softball', 'firestar', 'melee', 'masstiff', 'mgl', 'r-101', 'wingman', 'invalid', 'thunderbolt', 'dmr', 'electric smoke', 'cold war', 'satchel', 'eva-8 auto', 'mozambique', 'wingman elite', 'gravity star', 'pulse blade', 'archer', 'outOfBounds', 'mind crime', 'devotion', 'fall', 'p2016', 'arc grenade', 'hemlok', 'phase shift']
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
@stats.autocomplete("servername")
async def autocomplete_server(self, interaction: discord.Interaction, current: str) -> list[app_commands.Choice[str]]:
data = []
servers = requests.get("https://tone.sleepycat.date/v2/client/servers").json()
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
async def setup(client):
await client.add_cog(SlashStats(client))