diff options
author | AnInternetTroll <lucafulger@gmail.com> | 2020-06-29 13:25:24 +0000 |
---|---|---|
committer | AnInternetTroll <lucafulger@gmail.com> | 2020-06-29 13:25:24 +0000 |
commit | ac8580d300a00e874366a465bd8e1e56e90f15fa (patch) | |
tree | 5505966c3fc9e694cc264cc8f55f004255d2c9de | |
parent | 1e2c28b9d7467f5c08466b770e1d61d67d197065 (diff) | |
download | steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar.gz steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar.bz2 steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar.lz steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar.xz steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.tar.zst steve-bot-ac8580d300a00e874366a465bd8e1e56e90f15fa.zip |
Added xboxpresence command
-rwxr-xr-x | cogs/general.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cogs/general.py b/cogs/general.py index 9fc8f5c..57bf044 100755 --- a/cogs/general.py +++ b/cogs/general.py @@ -3,6 +3,7 @@ import discord import datetime
import requests
import json
+import dateutil.parser
def dump(obj):
output = ""
@@ -150,5 +151,41 @@ class General(commands.Cog): embed.add_field(name="Reputation", value=reputation, inline=True)
await ctx.send(embed=embed)
+ @commands.command()
+ async def xboxpresence(self, ctx, *, gamertag=None):
+ if not gamertag:
+ await ctx.send("You need to specify a gamer, gamer")
+ return
+
+ r = requests.get(f"https://xbl-api.prouser123.me/presence/gamertag/{gamertag}")
+ gamer = json.loads(r.text)
+
+ try:
+ await ctx.send(f"{gamer['error']}: {gamer['message']}")
+ return
+ except KeyError:
+ pass
+
+ state = gamer["state"]
+
+ try:
+ game = json.loads(requests.get(f"https://xbl-api.prouser123.me/titleinfo/{gamer['lastSeen']['titleId']}").text)
+ gameName = game["titles"][0]["name"]
+ gamePic = game["titles"][0]["images"][4]["url"]
+ timestamp = dateutil.parser.isoparse(gamer["lastSeen"]["timestamp"])
+ lastSeen = True
+ except Exception as e:
+ print(e)
+ lastSeen = False
+
+ if lastSeen:
+ embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=timestamp)
+ embed.set_thumbnail(url=gamePic)
+ embed.add_field(name="Game", value=gameName, inline=True)
+ await ctx.send(embed=embed)
+ else:
+ embed=discord.Embed(title=gamer["gamertag"], description=state, timestamp=ctx.message.created_at)
+ await ctx.send(embed=embed)
+
def setup(bot):
bot.add_cog(General(bot))
|