Skip to content

Commit

Permalink
Merge pull request #213 from Onii-Chan-Discord/patch-1
Browse files Browse the repository at this point in the history
Update userinfo!
  • Loading branch information
Dhruvacube authored Oct 15, 2021
2 parents 5af4b5d + 7e46775 commit e9eee80
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 7 deletions.
85 changes: 78 additions & 7 deletions minato_namikaze/bot_files/cogs/info/serverinfo.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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 = "<t:{}:R>".format(user_c_converter)
if user.joined_at is not None:
since_joined = "<t:{}:R>".format(user_j_converter)
user_joined = "<t:{}:D>".format(user_j_converter)
else:
since_joined = "?"
user_joined = ("Unknown")
user_created = "<t:{}:D>".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)
Expand Down Expand Up @@ -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"<t:{round(joined)}:D>")
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"<t:{round(created)}:D>")
# embed.add_field(name=f"📅 Created On", value=created_on)

if uuser.banner:
embed.set_image(url=uuser.banner)
Expand Down
23 changes: 23 additions & 0 deletions minato_namikaze/bot_files/lib/util/util.py
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit e9eee80

Please sign in to comment.