convert ffxiv to a slash command
This commit is contained in:
parent
7cadd3f2c8
commit
c2a4054e06
@ -1,5 +1,6 @@
|
||||
#!/usr/local/bin/python
|
||||
from discord.ext import commands
|
||||
import core_utils
|
||||
import discord
|
||||
import os
|
||||
import random
|
||||
|
@ -1,3 +1,4 @@
|
||||
from discord.commands import Option
|
||||
from discord.ext import commands
|
||||
import core_utils
|
||||
import discord
|
||||
@ -7,29 +8,42 @@ class Games(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot: commands.Bot = bot
|
||||
|
||||
@commands.command(name="bf5")
|
||||
async def bf5(self, ctx: commands.Context):
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
name="bf5",
|
||||
description="Query the game's API for data about a player",
|
||||
)
|
||||
async def bf5(self, ctx: commands.Context, player):
|
||||
import bf5
|
||||
|
||||
try:
|
||||
await ctx.reply(embed=bf5.get_player(ctx.message.content.split()[1]))
|
||||
except Exception:
|
||||
await ctx.defer()
|
||||
embed = bf5.get_player(player)
|
||||
await ctx.send_followup(embed=embed)
|
||||
except Exception as e:
|
||||
await ctx.send(
|
||||
"I encountered an error while searching for that player.\nPlease check that your player name is spelled correctly"
|
||||
e
|
||||
# "I encountered an error while searching for that player.\nPlease check that your player name is spelled correctly"
|
||||
)
|
||||
|
||||
@commands.command(name="ffxiv")
|
||||
@commands.slash_command(
|
||||
guild_ids=None,
|
||||
name="ffxiv",
|
||||
description="Query the game's API for data about a player",
|
||||
)
|
||||
async def ffxiv(self, ctx: commands.Context, first_name, last_name, server):
|
||||
import ffxiv
|
||||
|
||||
async with ctx.message.channel.typing():
|
||||
try:
|
||||
name = "%s %s" % (first_name, last_name)
|
||||
await ctx.reply(embed=ffxiv.make_request(name=name, server=server))
|
||||
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"
|
||||
)
|
||||
try:
|
||||
name = " ".join([first_name, last_name])
|
||||
embed = ffxiv.make_request(name=name, server=server)
|
||||
|
||||
await ctx.defer()
|
||||
await ctx.send_followup(embed=embed)
|
||||
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"
|
||||
)
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
@ -14,16 +14,12 @@ def make_request(name, server):
|
||||
server,
|
||||
token,
|
||||
)
|
||||
# print(player_search)
|
||||
player_id = list(
|
||||
filter(
|
||||
lambda x: server.lower() in x["Server"].lower(),
|
||||
requests.get(player_search).json()["Results"],
|
||||
)
|
||||
)[0]["ID"]
|
||||
import pprint
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=2, compact=True)
|
||||
|
||||
# if adding extended=1 to the query, you'll see some image files, eg. /cj/1/blackmage.png
|
||||
# prepend these with https://xivapi.com/ to get a useable url
|
||||
@ -32,11 +28,8 @@ def make_request(name, server):
|
||||
player_id,
|
||||
token,
|
||||
)
|
||||
# print(request_url)
|
||||
player_blob = requests.get(request_url).json()
|
||||
character = player_blob["Character"]
|
||||
# pp.pprint(player_blob)
|
||||
# pp.pprint(character)
|
||||
|
||||
current_class = character["ActiveClassJob"]
|
||||
current_class_name = current_class["Job"]["Name"]
|
||||
@ -103,5 +96,4 @@ def make_request(name, server):
|
||||
name=job["Job"]["Abbreviation"], value=job["Level"], inline=True
|
||||
)
|
||||
|
||||
# embed.set_footer(text='Feel free to use my refer a friend code: P9CQ9JUT')
|
||||
return embed
|
||||
|
Loading…
x
Reference in New Issue
Block a user