whois command + fix timeformatter for diff strubgs

pull/3/head
Stijn De Clercq 2020-10-23 19:33:01 +02:00
parent f6c324d656
commit f102faaf7e
4 changed files with 42 additions and 7 deletions

View File

@ -3,7 +3,7 @@ from decorators import help
import discord import discord
from discord.ext import commands from discord.ext import commands
from enums.help_categories import Category 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 from functions.database import memes, githubs, twitch, dadjoke
import json import json
import os import os
@ -150,6 +150,39 @@ class ModCommands(commands.Cog):
twitch.add(userid, link) twitch.add(userid, link)
await ctx.send("{}'s Twitch is toegevoegd aan de database.".format(self.utilsCog.getDisplayName(ctx, userid))) 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 # 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): async def sendDm(self, userid, message: str):
user = self.client.get_user(int(userid)) user = self.client.get_user(int(userid))

View File

@ -35,7 +35,8 @@ allowedChannels = {
"freegames": 705745297908826113, "freegames": 705745297908826113,
"bot-commandsCOCGI": 714170653124722738, "bot-commandsCOCGI": 714170653124722738,
"generalZandbak": 728361031008780422, "generalZandbak": 728361031008780422,
"freegamesZandbak": 728545397127118898 "freegamesZandbak": 728545397127118898,
"spelenZandbak": 769248992957038612
} }
creationDate = 1582243200 creationDate = 1582243200

View File

@ -108,6 +108,7 @@
"twitch add": "Voegt jouw eigen Twitch toe aan de lijst.\nZowel ``twitch.tv/username`` als ``username`` werken.", "twitch add": "Voegt jouw eigen Twitch toe aan de lijst.\nZowel ``twitch.tv/username`` als ``username`` werken.",
"unload": "Verwijdert [Cog].", "unload": "Verwijdert [Cog].",
"unload all": "Verwijdert alle cogs.", "unload all": "Verwijdert alle cogs.",
"whois": "Toont de info van [@User]",
"xp": "Bekijk je huidige aantal berichten en xp.", "xp": "Bekijk je huidige aantal berichten en xp.",
"yes/no": "Didier helpt je met keuzes maken." "yes/no": "Didier helpt je met keuzes maken."
} }

View File

@ -11,7 +11,7 @@ def epochToDate(epochTimeStamp, strFormat="%m/%d/%Y om %H:%M:%S"):
diff = now - updateTime diff = now - updateTime
updateFormatted = str(updateTime.strftime(strFormat)) updateFormatted = str(updateTime.strftime(strFormat))
timeAgo = str(time.strftime('%H:%M:%S', time.gmtime(diff.total_seconds()))) 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(): def dateTimeNow():
@ -51,8 +51,8 @@ def timeIn(seconds, unit):
# Creates a string representation based on Days/Hours/Minutes/Seconds # Creates a string representation based on Days/Hours/Minutes/Seconds
def diffDayBasisString(timestamp): def diffDayBasisString(timestamp):
if isinstance(timestamp, int): if isinstance(timestamp, int):
timestamp = datetime.datetime.fromtimestamp(timestamp) timestamp = epochToDate(timestamp)["dateDT"]
now = datetime.datetime.fromtimestamp(time.time()) now = dateTimeNow()
diff = dateutil.relativedelta.relativedelta(now, timestamp) diff = dateutil.relativedelta.relativedelta(now, timestamp)
timeList = [] timeList = []
@ -79,8 +79,8 @@ def diffDayBasisString(timestamp):
def diffYearBasisString(timestamp): def diffYearBasisString(timestamp):
if isinstance(timestamp, int): if isinstance(timestamp, int):
timestamp = datetime.datetime.fromtimestamp(timestamp) timestamp = epochToDate(timestamp)["dateDT"]
now = datetime.datetime.fromtimestamp(time.time()) now = dateTimeNow()
diff = dateutil.relativedelta.relativedelta(now, timestamp) diff = dateutil.relativedelta.relativedelta(now, timestamp)
timeList = [] timeList = []