Documentation
This commit is contained in:
parent
35a103520f
commit
54dbd48122
@ -104,7 +104,12 @@ def get_help_message(method):
|
|||||||
'\nUsage: !weather Berkeley'
|
'\nUsage: !weather Berkeley'
|
||||||
],
|
],
|
||||||
'pout': [
|
'pout': [
|
||||||
'Returns the URL for an anime girl pouting you filthy weeb'
|
'Returns the URL for an anime girl pouting you filthy weeb\n',
|
||||||
|
'Usage: !pout'
|
||||||
|
],
|
||||||
|
'quake': [
|
||||||
|
'Returns player stats for a quake champions account\n'
|
||||||
|
'Usage: !quake <player name>'
|
||||||
],
|
],
|
||||||
'smug': [
|
'smug': [
|
||||||
'Returns the URL for smug anime girl'
|
'Returns the URL for smug anime girl'
|
||||||
@ -127,7 +132,7 @@ def get_help_message(method):
|
|||||||
|
|
||||||
def get_help_embed(client):
|
def get_help_embed(client):
|
||||||
categories = {
|
categories = {
|
||||||
'fun': ['clap', 'birb', 'dog', 'excuse', 'greentext', 'lewd', 'message', 'homepage', 'pout', 'smug'],
|
'fun': ['clap', 'birb', 'dog', 'excuse', 'greentext', 'lewd', 'message', 'homepage', 'pout', 'smug', 'quake'],
|
||||||
'util': ['8ball', 'decide', 'wallpaper', 'weather', 'stock', 'tts', 'issue'],
|
'util': ['8ball', 'decide', 'wallpaper', 'weather', 'stock', 'tts', 'issue'],
|
||||||
'users': ['help', 'invite', 'purge', 'roles', 'source', 'minecraft'],
|
'users': ['help', 'invite', 'purge', 'roles', 'source', 'minecraft'],
|
||||||
'admin': ['emoji', 'cleanup']
|
'admin': ['emoji', 'cleanup']
|
||||||
|
47
app/quake.py
47
app/quake.py
@ -4,18 +4,29 @@ import discord
|
|||||||
import help_methods
|
import help_methods
|
||||||
|
|
||||||
def parse_message(message):
|
def parse_message(message):
|
||||||
|
"""
|
||||||
|
parse_message(message)
|
||||||
|
|
||||||
|
Handles the message and looks for a plaer name.
|
||||||
|
"""
|
||||||
if len(message.content.split()) == 1:
|
if len(message.content.split()) == 1:
|
||||||
return help_methods.get_help_message('quake')
|
return help_methods.get_help_message('quake')
|
||||||
|
|
||||||
# Return the player's name
|
# Return the player's name
|
||||||
name = message.content.split()[1]
|
name = message.content.split()[1]
|
||||||
if len(message.content.split()) > 1:
|
if len(message.content.split()) > 1:
|
||||||
name = '%20'.join(message.content.split()[1:])
|
name = '%20'.join(message.content.split()[1:])
|
||||||
|
|
||||||
return get_stats(player=name)
|
return get_stats(player=name)
|
||||||
|
|
||||||
|
|
||||||
def get_stats(player):
|
def get_stats(player):
|
||||||
|
"""
|
||||||
|
get_stats(player)
|
||||||
|
|
||||||
|
Makes the request to stats.quake.com and returns an embed object with a
|
||||||
|
bunch of data about the player
|
||||||
|
"""
|
||||||
base_url = 'https://stats.quake.com/api/v2/'
|
base_url = 'https://stats.quake.com/api/v2/'
|
||||||
player_endpoint = "Player/Stats?name={}".format(player)
|
player_endpoint = "Player/Stats?name={}".format(player)
|
||||||
|
|
||||||
@ -38,7 +49,6 @@ def create_embed(stats):
|
|||||||
object
|
object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# Parse the json and pull out the numbers we want
|
# Parse the json and pull out the numbers we want
|
||||||
champ_name, play_time = get_favorite_champion(stats)
|
champ_name, play_time = get_favorite_champion(stats)
|
||||||
fav_weapon, fav_weapon_kills = get_favorite_weapon(stats)
|
fav_weapon, fav_weapon_kills = get_favorite_weapon(stats)
|
||||||
@ -53,11 +63,11 @@ def create_embed(stats):
|
|||||||
name="\nShowing stats for {}".format(stats['name']),
|
name="\nShowing stats for {}".format(stats['name']),
|
||||||
icon_url="https://stats.quake.com/icons/{}.png".format(stats['playerLoadOut']['iconId'])
|
icon_url="https://stats.quake.com/icons/{}.png".format(stats['playerLoadOut']['iconId'])
|
||||||
)
|
)
|
||||||
|
|
||||||
embed.add_field(name="Current level:", value=stats['playerLevelState']['level'])
|
embed.add_field(name="Current level:", value=stats['playerLevelState']['level'])
|
||||||
embed.add_field(name="Total XP:", value=stats['playerLevelState']['exp'])
|
embed.add_field(name="Total XP:", value=stats['playerLevelState']['exp'])
|
||||||
embed.add_field(name="K/D:", value=kd_ratio)
|
embed.add_field(name="K/D:", value=kd_ratio)
|
||||||
|
|
||||||
embed.add_field(name="\u200b", value='\u200b', inline=False)
|
embed.add_field(name="\u200b", value='\u200b', inline=False)
|
||||||
|
|
||||||
embed.add_field(name="Favorite Champion:", value=champ_name)
|
embed.add_field(name="Favorite Champion:", value=champ_name)
|
||||||
@ -69,11 +79,18 @@ def create_embed(stats):
|
|||||||
embed.add_field(name="Num of kills with it:", value=fav_weapon_kills)
|
embed.add_field(name="Num of kills with it:", value=fav_weapon_kills)
|
||||||
|
|
||||||
embed.set_footer(text="Stats pulled from https://stats.quake.com", icon_url='https://stats.quake.com/icons/profile_icon_cbt_participant.png')
|
embed.set_footer(text="Stats pulled from https://stats.quake.com", icon_url='https://stats.quake.com/icons/profile_icon_cbt_participant.png')
|
||||||
|
|
||||||
return embed
|
return embed
|
||||||
|
|
||||||
|
|
||||||
def get_favorite_champion(blob):
|
def get_favorite_champion(blob):
|
||||||
|
"""
|
||||||
|
get_favorite_champion(blob)
|
||||||
|
|
||||||
|
Takes one argument, a large json data set from the stats API and parses it
|
||||||
|
to figure out who the players favorite champion is. Stores all the data
|
||||||
|
in a temp dictionary, play_times, then grabs the max value from it
|
||||||
|
"""
|
||||||
play_times = {}
|
play_times = {}
|
||||||
all_champions = blob['playerProfileStats']['champions']
|
all_champions = blob['playerProfileStats']['champions']
|
||||||
|
|
||||||
@ -86,13 +103,20 @@ def get_favorite_champion(blob):
|
|||||||
|
|
||||||
champion_play_time = max(play_times.values()) # maximum value
|
champion_play_time = max(play_times.values()) # maximum value
|
||||||
champion_name = [k for k, v in play_times.items() if v == champion_play_time][0] # getting all keys containing the `maximum`
|
champion_name = [k for k, v in play_times.items() if v == champion_play_time][0] # getting all keys containing the `maximum`
|
||||||
|
|
||||||
# Convert play_time from miliseconds to hours
|
# Convert play_time from miliseconds to hours
|
||||||
champion_play_time = round(float(champion_play_time)/(1000*60*60), 2)
|
champion_play_time = round(float(champion_play_time)/(1000*60*60), 2)
|
||||||
return(champion_name, champion_play_time)
|
return(champion_name, champion_play_time)
|
||||||
|
|
||||||
|
|
||||||
def get_favorite_weapon(blob):
|
def get_favorite_weapon(blob):
|
||||||
|
"""
|
||||||
|
get_favorite_weapon(blob)
|
||||||
|
|
||||||
|
Takes one argument, a large json data set from the stats API and parses it
|
||||||
|
to figure out what the players favorite weapon is. Stores all the data
|
||||||
|
in a temp dictionary, weapon_stats, then grabs the max value from it
|
||||||
|
"""
|
||||||
weapon_stats = {}
|
weapon_stats = {}
|
||||||
all_champions = blob['playerProfileStats']['champions']
|
all_champions = blob['playerProfileStats']['champions']
|
||||||
|
|
||||||
@ -105,12 +129,17 @@ def get_favorite_weapon(blob):
|
|||||||
|
|
||||||
total_kills = max(weapon_stats.values()) # maximum value
|
total_kills = max(weapon_stats.values()) # maximum value
|
||||||
weapon_name = [k for k, v in weapon_stats.items() if v == total_kills][0] # getting all keys containing the `maximum`
|
weapon_name = [k for k, v in weapon_stats.items() if v == total_kills][0] # getting all keys containing the `maximum`
|
||||||
|
|
||||||
return(weapon_name, total_kills)
|
return(weapon_name, total_kills)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_kd(blob):
|
def get_kd(blob):
|
||||||
|
"""
|
||||||
|
get_kd(blob)
|
||||||
|
|
||||||
|
Takes one argument, a large json data set from the stats API and parses it
|
||||||
|
to figure the players total K/D ratio
|
||||||
|
"""
|
||||||
total_kills = 0
|
total_kills = 0
|
||||||
total_deaths = 0
|
total_deaths = 0
|
||||||
all_champions = blob['playerProfileStats']['champions']
|
all_champions = blob['playerProfileStats']['champions']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user