Adding battlefield 5 api stuff
This commit is contained in:
parent
0de4812779
commit
cdd088aef1
@ -86,6 +86,7 @@ def random_dog_reddit():
|
||||
'tippytaps',
|
||||
'vizsla',
|
||||
'zoomies',
|
||||
'shiba',
|
||||
]
|
||||
)
|
||||
|
||||
|
63
app/bf5.py
Normal file
63
app/bf5.py
Normal file
@ -0,0 +1,63 @@
|
||||
import requests, json, pprint, discord
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def get_player(player):
|
||||
# try:
|
||||
url = "https://battlefieldtracker.com/bfv/profile/origin/" + player + "/overview"
|
||||
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' }
|
||||
response = requests.get(url, headers=headers).text
|
||||
soup = BeautifulSoup(response, "html.parser")
|
||||
script = soup.find_all("script")
|
||||
|
||||
jsonstring = str(script[1])
|
||||
jsonstring = jsonstring[33:-131]
|
||||
data = json.loads(jsonstring)
|
||||
|
||||
# Get Player Data
|
||||
origin_name = 'bfv|origin|' + player
|
||||
|
||||
base_stat_blob = data['stats-v2']['standardProfiles'][origin_name]
|
||||
account_name = base_stat_blob['platformInfo']['platformUserHandle']
|
||||
avatar_url = base_stat_blob['platformInfo']['avatarUrl']
|
||||
|
||||
stats_overview = base_stat_blob['segments'][0]['stats']
|
||||
rank = stats_overview['rank']
|
||||
rank_title = rank['metadata']['label']
|
||||
rank_number = rank['displayValue']
|
||||
|
||||
# Build the embed
|
||||
embed = discord.Embed(description='-------', color=15105570, type="rich")
|
||||
embed.set_thumbnail(url=avatar_url)
|
||||
embed.set_author(name="Battlefield V stats for %s" % account_name)
|
||||
embed.add_field(name="**Rank**", value="%s, %s" % (rank_number, rank_title), inline=False)
|
||||
|
||||
gameplay_stats = [
|
||||
'scorePerMinute',
|
||||
'kdRatio',
|
||||
'assists',
|
||||
'shotsAccuracy',
|
||||
'killStreak',
|
||||
'dogtagsTaken',
|
||||
'headshots',
|
||||
'longestHeadshot',
|
||||
'heals',
|
||||
'revives',
|
||||
'revivesRecieved',
|
||||
'resupplies',
|
||||
'aceSquad',
|
||||
'wlPercentage',
|
||||
]
|
||||
|
||||
for stat in gameplay_stats:
|
||||
# print(stat)
|
||||
embed.add_field(name="**%s**" % stat.title(), value=stats_overview[stat]['displayValue'], inline=False)
|
||||
# embed.add_field(name='Raw value', value=stats_overview[stat]['displayValue'], inline=True)
|
||||
# embed.add_field(name='Global Percentile', value=stats_overview[stat]['percentile'], inline=True)
|
||||
return embed
|
||||
# except Exception:
|
||||
# return 'nope'
|
||||
|
||||
# assault_stats = base_stat_blob['segments'][9]
|
||||
# medic_stats = base_stat_blob['segments'][10]
|
||||
|
||||
# pp.pprint(medic_stats)
|
11
app/bot.py
11
app/bot.py
@ -442,13 +442,20 @@ async def eight_ball(ctx):
|
||||
|
||||
await ctx.send(":8ball: %s :8ball:" % result)
|
||||
|
||||
@bot.command(name='bf5')
|
||||
async def bf5(ctx):
|
||||
import bf5
|
||||
try:
|
||||
await ctx.send(embed=bf5.get_player(ctx.message.content.split()[1]))
|
||||
except Exception:
|
||||
await ctx.send("I encountered an error while searching for that player.\nPlease check that your player name is spelled correctly")
|
||||
|
||||
@bot.command(name='ffxiv')
|
||||
async def ffxiv(ctx):
|
||||
import ffxiv
|
||||
async with ctx.message.channel.typing():
|
||||
try:
|
||||
ffxiv_embed = ffxiv.parse_message(ctx.message.content)
|
||||
await ctx.send(embed=ffxiv_embed)
|
||||
await ctx.send(embed=ffxiv.parse_message(ctx.message.content))
|
||||
except Exception:
|
||||
await ctx.send("I encountered an error while searching for that player.\nPlease check that your player name and server are spelled correctly")
|
||||
|
||||
|
@ -25,6 +25,10 @@ def get_help_message(method):
|
||||
'Returns a random bird photo',
|
||||
'\nUsage: !birb'
|
||||
],
|
||||
'bf5': [
|
||||
'Returns some API stats about a battlefield 5 character',
|
||||
'\nUsage: !bf5 <your origin account name>'
|
||||
],
|
||||
'dale': [
|
||||
'Posts a photo or video of Dale, the goodest boy.',
|
||||
'\nUsage: !dale'
|
||||
@ -217,7 +221,7 @@ def get_help_message(method):
|
||||
|
||||
def get_help_embed(bot):
|
||||
categories = {
|
||||
'fun': ['ffxiv', 'clap', 'youtube', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'wink', 'verify', 'horny', 'wasted', 'simp', 'trackdays'],
|
||||
'fun': ['bf5', 'ffxiv', 'clap', 'youtube', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'wink', 'verify', 'horny', 'wasted', 'simp', 'trackdays'],
|
||||
'util': ['ask', 'corona', 'emoji', '8ball', 'decide', 'info', 'icon', 'wallpaper', 'stock', 'tts', 'issue'],
|
||||
'users': ['help', 'invite', 'purge', 'roles', 'source'],
|
||||
'pictures of animals': ['birb', 'redpanda,' 'dale', 'dog', 'rat', 'koala', 'panda', 'raccoon', 'fox', 'cat', 'kangaroo'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user