diff --git a/minato_namikaze/bot_files/cogs/info/serverinfo.py b/minato_namikaze/bot_files/cogs/info/serverinfo.py index c05f9ae4..092732ee 100644 --- a/minato_namikaze/bot_files/cogs/info/serverinfo.py +++ b/minato_namikaze/bot_files/cogs/info/serverinfo.py @@ -1,12 +1,14 @@ # Discord Imports import datetime import time +from datetime import timezone +import re import discord from discord import Spotify from discord.ext import commands -from ...lib import Embed +from ...lib import Embed, filter_invites class Info(commands.Cog): @@ -208,6 +210,26 @@ async def server_banner(self, ctx): async def user(self, ctx, *, user: discord.Member = None): """ Get user information """ user = user or ctx.author + names, nicks= await self.get_names_and_nicks(user) + + """Timestamp stuff""" + dt = user.joined_at + dt1 = user.created_at + unix_ts_utc = dt.replace(tzinfo=timezone.utc).timestamp() + unix_ts_utc1 = dt1.replace(tzinfo=timezone.utc).timestamp() + user_c_converter = int(unix_ts_utc1) + user_j_converter = int(unix_ts_utc) + + since_created = "".format(user_c_converter) + if user.joined_at is not None: + since_joined = "".format(user_j_converter) + user_joined = "".format(user_j_converter) + else: + since_joined = "?" + user_joined = ("Unknown") + user_created = "".format(user_c_converter) + created_on = ("{} - ({})").format(since_created, user_created) + joined_on = ("{} - ({})\n").format(since_joined, user_joined) """ to fetch user (for banner)""" uuser = await self.bot.fetch_user(user.id) @@ -244,14 +266,63 @@ async def user(self, ctx, *, user: discord.Member = None): embed.set_thumbnail(url=user.avatar.url) embed.add_field(name="🔹 User", value=user, inline=True) - embed.add_field(name="✏️ Name", value=user.display_name) - embed.add_field(name="🔸 Roles", value=show_roles, inline=False) - joined = user.joined_at.timestamp() - embed.add_field(name="📅 Joined On", value=f"") + if names: + name_name = "**Previous Names:**" if len(names) > 1 else "**Previous Name:**" + name_val = filter_invites(", ".join(names)) + prev_names_val = "{}\n{}".format( + name_name, + name_val, + ) + + else: + prev_names_val = "" + + if nicks: + nick_name = "**Previous Nicknames:**" if len(nicks) > 1 else "**Previous Nickname:**" + nick_val = filter_invites(", ".join(nicks)) + prev_nicks_val = "{}\n{}\n".format( + nick_name, + nick_val, + ) + + else: + prev_nicks_val = "" + + embed.add_field( + name="**__User info__**", + value=( + "🔸 Roles: {}\n" + "📅 Joined On {}" + "{}" + ).format( + show_roles, + joined_on, + prev_nicks_val + ) + ) + embed.add_field( + name="**__Member Info__**", + value=( + "✏️ Name: {}\n" + "{}: {}\n" + "📅 Created On: {}" + ).format( + user.display_name, + prev_names_val, + created_on + ) + ) + + # embed.add_field(name="✏️ Name", value=user.display_name) + + # embed.add_field(name=name_name, value=name_val) + + # embed.add_field(name="🔸 Roles", value=show_roles, inline=False) + + # embed.add_field(name="📅 Joined On", value=joined_on) - created = user.created_at.timestamp() - embed.add_field(name=f"📅 Created On", value=f"") + # embed.add_field(name=f"📅 Created On", value=created_on) if uuser.banner: embed.set_image(url=uuser.banner) diff --git a/minato_namikaze/bot_files/lib/util/util.py b/minato_namikaze/bot_files/lib/util/util.py index b8aa15af..6b2bc81d 100644 --- a/minato_namikaze/bot_files/lib/util/util.py +++ b/minato_namikaze/bot_files/lib/util/util.py @@ -1,9 +1,32 @@ import random import discord +import re from .vars import ChannelAndMessageId +INVITE_URL_RE = re.compile(r"(discord\.(?:gg|io|me|li)|discord(?:app)?\.com\/invite)\/(\S+)", re.I) + + +def filter_invites(to_filter: str) -> str: + """Get a string with discord invites sanitized. + + Will match any discord.gg, discordapp.com/invite, discord.com/invite, discord.me, or discord.io/discord.li + invite URL. + + Parameters + ---------- + to_filter : str + The string to filter. + + Returns + ------- + str + The sanitized string. + + """ + return INVITE_URL_RE.sub("[SANITIZED INVITE]", to_filter) + def convert(time): pos = ["s", "m", "h", "d"]