convert ffxiv to a slash command
This commit is contained in:
parent
7cadd3f2c8
commit
c2a4054e06
@ -1,5 +1,6 @@
|
|||||||
#!/usr/local/bin/python
|
#!/usr/local/bin/python
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
import core_utils
|
||||||
import discord
|
import discord
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from discord.commands import Option
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
import core_utils
|
import core_utils
|
||||||
import discord
|
import discord
|
||||||
@ -7,29 +8,42 @@ class Games(commands.Cog):
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot: commands.Bot = bot
|
self.bot: commands.Bot = bot
|
||||||
|
|
||||||
@commands.command(name="bf5")
|
@commands.slash_command(
|
||||||
async def bf5(self, ctx: commands.Context):
|
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
|
import bf5
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ctx.reply(embed=bf5.get_player(ctx.message.content.split()[1]))
|
await ctx.defer()
|
||||||
except Exception:
|
embed = bf5.get_player(player)
|
||||||
|
await ctx.send_followup(embed=embed)
|
||||||
|
except Exception as e:
|
||||||
await ctx.send(
|
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):
|
async def ffxiv(self, ctx: commands.Context, first_name, last_name, server):
|
||||||
import ffxiv
|
import ffxiv
|
||||||
|
|
||||||
async with ctx.message.channel.typing():
|
try:
|
||||||
try:
|
name = " ".join([first_name, last_name])
|
||||||
name = "%s %s" % (first_name, last_name)
|
embed = ffxiv.make_request(name=name, server=server)
|
||||||
await ctx.reply(embed=ffxiv.make_request(name=name, server=server))
|
|
||||||
except Exception:
|
await ctx.defer()
|
||||||
await ctx.send(
|
await ctx.send_followup(embed=embed)
|
||||||
"I encountered an error while searching for that player.\nPlease check that your player name and server are spelled correctly"
|
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):
|
def setup(bot):
|
||||||
|
@ -14,16 +14,12 @@ def make_request(name, server):
|
|||||||
server,
|
server,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
# print(player_search)
|
|
||||||
player_id = list(
|
player_id = list(
|
||||||
filter(
|
filter(
|
||||||
lambda x: server.lower() in x["Server"].lower(),
|
lambda x: server.lower() in x["Server"].lower(),
|
||||||
requests.get(player_search).json()["Results"],
|
requests.get(player_search).json()["Results"],
|
||||||
)
|
)
|
||||||
)[0]["ID"]
|
)[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
|
# 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
|
# prepend these with https://xivapi.com/ to get a useable url
|
||||||
@ -32,11 +28,8 @@ def make_request(name, server):
|
|||||||
player_id,
|
player_id,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
# print(request_url)
|
|
||||||
player_blob = requests.get(request_url).json()
|
player_blob = requests.get(request_url).json()
|
||||||
character = player_blob["Character"]
|
character = player_blob["Character"]
|
||||||
# pp.pprint(player_blob)
|
|
||||||
# pp.pprint(character)
|
|
||||||
|
|
||||||
current_class = character["ActiveClassJob"]
|
current_class = character["ActiveClassJob"]
|
||||||
current_class_name = current_class["Job"]["Name"]
|
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
|
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
|
return embed
|
||||||
|
Loading…
x
Reference in New Issue
Block a user