Merge pull request #3 from stijndcl/whois

Whois
pull/5/head
Stijn De Clercq 2020-10-23 19:37:22 +02:00 committed by GitHub
commit 9ba95a6a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 8 deletions

View File

@ -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))

View File

@ -57,7 +57,7 @@ class Utils(commands.Cog):
member = COC.get_member(int(memberid))
if member is not None:
return member.display_name
return "[Persoon die de server misschien geleaved is]"
return "[Persoon die de server misschien geleaved is | {}]".format(memberid)
mem = ctx.guild.get_member(int(memberid))
return mem.display_name

View File

@ -35,7 +35,8 @@ allowedChannels = {
"freegames": 705745297908826113,
"bot-commandsCOCGI": 714170653124722738,
"generalZandbak": 728361031008780422,
"freegamesZandbak": 728545397127118898
"freegamesZandbak": 728545397127118898,
"spelenZandbak": 769248992957038612
}
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.",
"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."
}

View File

@ -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 = []