about summary refs log tree commit diff stats
path: root/cogs
diff options
context:
space:
mode:
authorredcreeper14385 <mounderfod@gmail.com>2021-08-31 17:35:49 +0100
committerredcreeper14385 <mounderfod@gmail.com>2021-08-31 17:35:49 +0100
commit182580c3429d93e0d421bcfe32bc391842c946d5 (patch)
tree8c28f85e6687f9fa82018e804ffca70c0e94ad24 /cogs
parent215869f6d3c43ba7ebffb4735a9dfaaa69358adc (diff)
downloadtiny-potato-bot-182580c3429d93e0d421bcfe32bc391842c946d5.tar.gz
Add a modrinth user command
Diffstat (limited to 'cogs')
-rw-r--r--cogs/modrinth.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/cogs/modrinth.py b/cogs/modrinth.py
index 85ed972..dff091b 100644
--- a/cogs/modrinth.py
+++ b/cogs/modrinth.py
@@ -1,15 +1,15 @@
 import discord
 from discord.ext import commands
-import requests
+import requests, datetime, math
 
 class Modrinth(commands.Cog):
     def __init__(self, bot):
         self.bot = bot
 
-    @commands.command(name="modrinth", brief="Finds a given mod on Modrinth.", help="""Finds a given mod on Modrinth.
+    @commands.command(name="modrinthmod", brief="Finds a given mod on Modrinth.", help="""Finds a given mod on Modrinth.
     You can provide either the slug (`fabric-for-fabric`) or the project ID (`u6KTKg89`).
-    If you get a JSONDecodeError it's because the mod could not be found!""", aliases=['mr', 'modr'])
-    async def modrinth(self, ctx, mod): # 5da426
+    If you get a JSONDecodeError it's because the mod could not be found!""", aliases=['mrmod', 'modrmod'])
+    async def modrinth_mod(self, ctx, mod): # 5da426
         response = requests.get(f'https://api.modrinth.com/api/v1/mod/{mod}').json()
         embed = discord.Embed(title = response['title'], url=f'https://modrinth.com/mod/{mod}', description = response['description'], color = 0x5da426)
         embed.set_thumbnail(url = response['icon_url'])
@@ -19,6 +19,20 @@ class Modrinth(commands.Cog):
         embed.set_footer(text='Tiny Potato Bot')
         await ctx.send(embed=embed)
 
+    @commands.command(name="modrinthuser", brief="Finds a given user on Modrinth.", help="""Finds a given user on Modrinth.
+        You can provide either the username (`redcreeper14385`) or the user ID (`pdimDmDX`).
+        If you get a JSONDecodeError it's because the user could not be found!""", aliases=['mruser', 'modruser'])
+    async def modrinth_user(self, ctx, user):  # 5da426
+        response = requests.get(f'https://api.modrinth.com/api/v1/user/{user}').json()
+        embed = discord.Embed(title=response['username'], url=f'https://modrinth.com/user/{user}',
+                              description=response['bio'], color=0x5da426)
+        embed.set_thumbnail(url=response['avatar_url'])
+        embed.add_field(name='User ID', value=response['id'], inline=True)
+        embed.add_field(name='Registered', value=f"<t:{math.trunc(datetime.datetime.fromisoformat(response['created'].replace('Z', '')).timestamp())}:R>", inline=True)
+        embed.add_field(name='Role', value=response['role'].capitalize(), inline=True)
+        embed.set_footer(text='Tiny Potato Bot')
+        await ctx.send(embed=embed)
+
 
 def setup(bot):
     bot.add_cog(Modrinth(bot))
\ No newline at end of file