From f102faaf7e431ccc417c8482c464c340045b75af Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Fri, 23 Oct 2020 19:33:01 +0200 Subject: [PATCH] whois command + fix timeformatter for diff strubgs --- cogs/modCommands.py | 35 ++++++++++++++++++++++++++++++++++- data/constants.py | 3 ++- files/help.json | 1 + functions/timeFormatters.py | 10 +++++----- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cogs/modCommands.py b/cogs/modCommands.py index 7b75beb..e8c38ae 100644 --- a/cogs/modCommands.py +++ b/cogs/modCommands.py @@ -3,7 +3,7 @@ from decorators import help import discord from discord.ext import commands from enums.help_categories import Category -from functions import checks, config +from functions import checks, config, timeFormatters from functions.database import memes, githubs, twitch, dadjoke import json import os @@ -150,6 +150,39 @@ class ModCommands(commands.Cog): twitch.add(userid, link) await ctx.send("{}'s Twitch is toegevoegd aan de database.".format(self.utilsCog.getDisplayName(ctx, userid))) + @commands.command(name="WhoIs", aliases=["Info"], usage="[@User]") + @help.Category(Category.Mod) + async def whois(self, ctx, user: discord.User): + embed = discord.Embed(colour=discord.Colour.blue()) + + embed.set_author(name=user.display_name, icon_url=user.avatar_url) + embed.add_field(name="Discriminator", value="#{}".format(user.discriminator)) + embed.add_field(name="Discord Id", value=user.id) + embed.add_field(name="Bot", value="Nee" if not user.bot else "Ja") + + created_local = timeFormatters.epochToDate(user.created_at.timestamp()) + + embed.add_field(name="Account Aangemaakt", value="{}\n({} Geleden)".format( + created_local["date"], timeFormatters.diffYearBasisString(round(created_local["dateDT"].timestamp())) + ), inline=False) + + # Check if the user is in the current guild + if ctx.guild is not None: + member_instance = ctx.guild.get_member(user.id) + + embed.add_field(name="Lid van {}".format(ctx.guild.name), value="Nee" if member_instance is None else "Ja") + + if member_instance is not None: + joined_local = timeFormatters.epochToDate(member_instance.joined_at.timestamp()) + + embed.add_field(name="Lid Geworden Op", value="{}\n({} Geleden)".format( + joined_local["date"], timeFormatters.diffYearBasisString(round(joined_local["dateDT"].timestamp())) + )) + + embed.add_field(name="Mention String", value=member_instance.mention, inline=False) + + await ctx.send(embed=embed) + # Send a DM to a user -- Can't re-use Utils cog in (un)load because the cog might not be loaded async def sendDm(self, userid, message: str): user = self.client.get_user(int(userid)) diff --git a/data/constants.py b/data/constants.py index e176948..9f71825 100644 --- a/data/constants.py +++ b/data/constants.py @@ -35,7 +35,8 @@ allowedChannels = { "freegames": 705745297908826113, "bot-commandsCOCGI": 714170653124722738, "generalZandbak": 728361031008780422, - "freegamesZandbak": 728545397127118898 + "freegamesZandbak": 728545397127118898, + "spelenZandbak": 769248992957038612 } creationDate = 1582243200 diff --git a/files/help.json b/files/help.json index 64ff0c9..8555073 100644 --- a/files/help.json +++ b/files/help.json @@ -108,6 +108,7 @@ "twitch add": "Voegt jouw eigen Twitch toe aan de lijst.\nZowel ``twitch.tv/username`` als ``username`` werken.", "unload": "Verwijdert [Cog].", "unload all": "Verwijdert alle cogs.", + "whois": "Toont de info van [@User]", "xp": "Bekijk je huidige aantal berichten en xp.", "yes/no": "Didier helpt je met keuzes maken." } \ No newline at end of file diff --git a/functions/timeFormatters.py b/functions/timeFormatters.py index 4e9801f..8cf2424 100644 --- a/functions/timeFormatters.py +++ b/functions/timeFormatters.py @@ -11,7 +11,7 @@ def epochToDate(epochTimeStamp, strFormat="%m/%d/%Y om %H:%M:%S"): diff = now - updateTime updateFormatted = str(updateTime.strftime(strFormat)) timeAgo = str(time.strftime('%H:%M:%S', time.gmtime(diff.total_seconds()))) - return {"date": updateFormatted, "timeAgo": timeAgo} + return {"date": updateFormatted, "dateDT": updateTime, "timeAgo": timeAgo} def dateTimeNow(): @@ -51,8 +51,8 @@ def timeIn(seconds, unit): # Creates a string representation based on Days/Hours/Minutes/Seconds def diffDayBasisString(timestamp): if isinstance(timestamp, int): - timestamp = datetime.datetime.fromtimestamp(timestamp) - now = datetime.datetime.fromtimestamp(time.time()) + timestamp = epochToDate(timestamp)["dateDT"] + now = dateTimeNow() diff = dateutil.relativedelta.relativedelta(now, timestamp) timeList = [] @@ -79,8 +79,8 @@ def diffDayBasisString(timestamp): def diffYearBasisString(timestamp): if isinstance(timestamp, int): - timestamp = datetime.datetime.fromtimestamp(timestamp) - now = datetime.datetime.fromtimestamp(time.time()) + timestamp = epochToDate(timestamp)["dateDT"] + now = dateTimeNow() diff = dateutil.relativedelta.relativedelta(now, timestamp) timeList = []