Add commands to return info on a user and process snowflakes
This commit is contained in:
parent
980d39005d
commit
945a8b850a
65
geeksbot/exts/inspect.py
Normal file
65
geeksbot/exts/inspect.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from geeksbot.imports.utils import process_snowflake
|
||||||
|
|
||||||
|
|
||||||
|
class Inspect(commands.Cog):
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.command(aliases=['u'])
|
||||||
|
async def user(self, ctx, member: discord.Member):
|
||||||
|
em = discord.Embed(style='rich',
|
||||||
|
title=f'{member.name}#{member.discriminator} ({member.display_name})',
|
||||||
|
description=f'({member.id})',
|
||||||
|
color=self.bot.embed_color)
|
||||||
|
em.set_thumbnail(url=f'{member.avatar_url}')
|
||||||
|
em.add_field(name=f'Highest Role:',
|
||||||
|
value=f'{member.top_role.mention}',
|
||||||
|
inline=True)
|
||||||
|
em.add_field(name=f'Bot:',
|
||||||
|
value=f'{member.bot}',
|
||||||
|
inline=True)
|
||||||
|
em.add_field(name=f'Joined Guild:',
|
||||||
|
value=f'{self.create_date_string(member.joined_at, ctx.message.created_at)}',
|
||||||
|
inline=False)
|
||||||
|
em.add_field(name=f'Joined Discord:',
|
||||||
|
value=f'{self.create_date_string(member.created_at, ctx.message.created_at)}',
|
||||||
|
inline=False)
|
||||||
|
em.add_field(name=f'Current Status:',
|
||||||
|
value=f'{member.status}',
|
||||||
|
inline=True)
|
||||||
|
em.add_field(name=f"Currently{' ' + member.activity.type.name.title() if member.activity else ''}:",
|
||||||
|
value=f"{member.activity.name if member.activity else 'Not doing anything important.'}",
|
||||||
|
inline=True)
|
||||||
|
count = 0
|
||||||
|
async for message in ctx.channel.history(after=(ctx.message.created_at - timedelta(hours=1))):
|
||||||
|
if message.author == member:
|
||||||
|
count += 1
|
||||||
|
em.add_field(name=f'Activity:',
|
||||||
|
value=f'{member.display_name} has sent {count} '
|
||||||
|
f'{"message" if count == 1 else "messages"} in the last hour to this channel.',
|
||||||
|
inline=False)
|
||||||
|
await ctx.send(embed=em)
|
||||||
|
|
||||||
|
@commands.command(aliases=['s'])
|
||||||
|
async def snowflake(self, ctx, snowflake: int):
|
||||||
|
try:
|
||||||
|
snowflake = int(snowflake)
|
||||||
|
except ValueError:
|
||||||
|
await ctx.send('That is not a valid snowflake')
|
||||||
|
if len(bin(snowflake))-2 < 63 or len(bin(snowflake))-2 > 64:
|
||||||
|
await ctx.send('That is not a valid snowflake')
|
||||||
|
creation_time, worker, process, counter = process_snowflake(snowflake)
|
||||||
|
em = discord.Embed(title=str(snowflake),
|
||||||
|
description=f'Created At: {creation_time.strftime("%c")}\n'
|
||||||
|
f'Worker: {worker}\n'
|
||||||
|
f'Process: {process}\n'
|
||||||
|
f'Increment Counter: {counter}',
|
||||||
|
color=self.bot.embed_color)
|
||||||
|
await ctx.send(em)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Inspect(bot))
|
||||||
@ -1,12 +1,28 @@
|
|||||||
import discord
|
import discord
|
||||||
import asyncio
|
import asyncio
|
||||||
import typing
|
import typing
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
async def get_guild_config(bot, guild_id):
|
async def get_guild_config(bot, guild_id):
|
||||||
guild_config = bot.cache.get()
|
guild_config = bot.cache.get()
|
||||||
|
|
||||||
|
|
||||||
|
def process_snowflake(snowflake: int) -> typing.Tuple[datetime, int, int, int]:
|
||||||
|
DISCORD_EPOCH = 1420070400000
|
||||||
|
TIME_BITS_LOC = 22
|
||||||
|
WORKER_ID_LOC = 17
|
||||||
|
WORKER_ID_MASK = 0x3E0000
|
||||||
|
PROCESS_ID_LOC = 12
|
||||||
|
PROCESS_ID_MASK = 0x1F000
|
||||||
|
INCREMENT_MASK = 0xFFF
|
||||||
|
creation_time = datetime.fromtimestamp((snowflake >> TIME_BITS_LOC) + DISCORD_EPOCH)
|
||||||
|
worker_id = (snowflake >> WORKER_ID_LOC) & WORKER_ID_MASK
|
||||||
|
process_id = (snowflake >> PROCESS_ID_LOC) & PROCESS_ID_MASK
|
||||||
|
counter = snowflake & INCREMENT_MASK
|
||||||
|
return creation_time, worker_id, process_id, counter
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyDefaultArgument
|
# noinspection PyDefaultArgument
|
||||||
def to_list_of_str(items, out: list = list(), level=1, recurse=0):
|
def to_list_of_str(items, out: list = list(), level=1, recurse=0):
|
||||||
# noinspection PyShadowingNames
|
# noinspection PyShadowingNames
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user