From 17b9ff54a4df10553951c6ff59165f0b2cfb6a51 Mon Sep 17 00:00:00 2001 From: ASF Codes <96375683+ASF007@users.noreply.github.com> Date: Sun, 3 Jul 2022 22:24:49 +0400 Subject: [PATCH 1/4] update: infraction info to use discord timestamps, remove unused import Additionally made `!inf` to invoke the help command if no sub cmds are passed. --- GearBot/Cogs/Infractions.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/GearBot/Cogs/Infractions.py b/GearBot/Cogs/Infractions.py index 81f60b2e..01f07218 100644 --- a/GearBot/Cogs/Infractions.py +++ b/GearBot/Cogs/Infractions.py @@ -1,10 +1,9 @@ -import asyncio import json import re import datetime import disnake -from disnake import Interaction +from disnake import Interaction, utils from disnake.ext import commands from disnake.ext.commands import BadArgument, Greedy, BucketType @@ -20,6 +19,12 @@ class Infractions(BaseCog): + + def inf_time(self, inf_timestamp: int): + """Returns the infraction time as discord timestamps.""" + long_dt_time = utils.format_dt(inf_timestamp, 'F') + relative_time = utils.format_dt(inf_timestamp, 'R') + return f"{long_dt_time} ({relative_time})" async def _warn(self, ctx, target, *, reason, message=True, dm_action=True): i = await InfractionUtils.add_infraction(ctx.guild.id, target.id, ctx.author.id, "Warn", reason) @@ -117,7 +122,8 @@ def check(interaction: Interaction): @commands.group(aliases=["infraction", "infractions"], invoke_without_command=True) async def inf(self, ctx: commands.Context): """inf_help""" - pass + if ctx.subcommand_passed is None: + await ctx.invoke(self.bot.get_command("help"), query="infraction") @inf.command() async def search(self, ctx: commands.Context, fields: commands.Greedy[InfSearchLocation] = None, *, @@ -272,13 +278,9 @@ async def info(self, ctx, infraction: ServerInfraction): embed.add_field(name=Translator.translate('user', ctx), value=Utils.clean_user(user)) embed.add_field(name=Translator.translate('mod_id', ctx), value=infraction.mod_id) embed.add_field(name=Translator.translate('user_id', ctx), value=infraction.user_id) - embed.add_field(name=Translator.translate('inf_added', ctx), - value=datetime.datetime.utcfromtimestamp(infraction.start).replace( - tzinfo=datetime.timezone.utc)) + embed.add_field(name=Translator.translate('inf_added', ctx), value=self.inf_time(infraction.start)) if infraction.end is not None: - embed.add_field(name=Translator.translate('inf_end', ctx), - value=datetime.datetime.utcfromtimestamp(infraction.end).replace( - tzinfo=datetime.timezone.utc)) + embed.add_field(name=Translator.translate('inf_end', ctx), value=self.inf_time(infraction.end)) embed.add_field(name=Translator.translate('inf_active', ctx), value=MessageUtils.assemble(ctx, 'YES' if infraction.active else 'NO', str(infraction.active).lower())) From ea65d71f96af123fc189f9cc8de90eca610e4165 Mon Sep 17 00:00:00 2001 From: Slurpcy Date: Sun, 9 Oct 2022 22:29:37 +0400 Subject: [PATCH 2/4] feat: Make gearbot auto join thread --- GearBot/Bot/GearBot.py | 3 +++ GearBot/Bot/TheRealGearBot.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/GearBot/Bot/GearBot.py b/GearBot/Bot/GearBot.py index 0d56c340..3d20cb08 100644 --- a/GearBot/Bot/GearBot.py +++ b/GearBot/Bot/GearBot.py @@ -76,4 +76,7 @@ async def on_error(self, event, *args, **kwargs): async def on_guild_update(self, before, after): await TheRealGearBot.on_guild_update(before, after) + async def on_thread_create(self, thread): + await TheRealGearBot.on_thread_create(self, thread) + #### reloading diff --git a/GearBot/Bot/TheRealGearBot.py b/GearBot/Bot/TheRealGearBot.py index 2a8e540b..7e7a9c44 100644 --- a/GearBot/Bot/TheRealGearBot.py +++ b/GearBot/Bot/TheRealGearBot.py @@ -15,7 +15,7 @@ import disnake import sentry_sdk from aiohttp import ClientOSError, ServerDisconnectedError -from disnake import Activity, Embed, Colour, Message, TextChannel, Forbidden, ConnectionClosed, Guild, NotFound +from disnake import Activity, Embed, Colour, Message, TextChannel, Thread, Forbidden, ConnectionClosed, Guild, NotFound from disnake.abc import PrivateChannel from disnake.ext import commands from disnake.ext.commands import UnexpectedQuoteError, ExtensionAlreadyLoaded, InvalidEndOfQuotedStringError @@ -102,6 +102,12 @@ async def message_flusher(): await asyncio.sleep(60) await DBUtils.flush() +async def on_thread_create(bot, thread: Thread): + if bot.user in thread.members: + return + else: + await thread.join() + async def on_message(bot, message:Message): if message.author.bot: if message.author.id == bot.user.id: From 8f5c746aa4a5f803b9211eb122db52ac416f016c Mon Sep 17 00:00:00 2001 From: ASF Codes <96375683+ASF007@users.noreply.github.com> Date: Sun, 12 Mar 2023 15:29:32 +0400 Subject: [PATCH 3/4] Remove: on_thread_create --- GearBot/Bot/GearBot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/GearBot/Bot/GearBot.py b/GearBot/Bot/GearBot.py index 3d20cb08..592db83a 100644 --- a/GearBot/Bot/GearBot.py +++ b/GearBot/Bot/GearBot.py @@ -76,7 +76,5 @@ async def on_error(self, event, *args, **kwargs): async def on_guild_update(self, before, after): await TheRealGearBot.on_guild_update(before, after) - async def on_thread_create(self, thread): - await TheRealGearBot.on_thread_create(self, thread) #### reloading From 0adc83eba5acdc370d881cb69fc256e293fa8c8a Mon Sep 17 00:00:00 2001 From: ASF Codes <96375683+ASF007@users.noreply.github.com> Date: Sun, 12 Mar 2023 15:30:26 +0400 Subject: [PATCH 4/4] Remove thread auto joining --- GearBot/Bot/TheRealGearBot.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/GearBot/Bot/TheRealGearBot.py b/GearBot/Bot/TheRealGearBot.py index 7e7a9c44..b4d4cc14 100644 --- a/GearBot/Bot/TheRealGearBot.py +++ b/GearBot/Bot/TheRealGearBot.py @@ -15,7 +15,7 @@ import disnake import sentry_sdk from aiohttp import ClientOSError, ServerDisconnectedError -from disnake import Activity, Embed, Colour, Message, TextChannel, Thread, Forbidden, ConnectionClosed, Guild, NotFound +from disnake import Activity, Embed, Colour, Message, TextChannel, Forbidden, ConnectionClosed, Guild, NotFound from disnake.abc import PrivateChannel from disnake.ext import commands from disnake.ext.commands import UnexpectedQuoteError, ExtensionAlreadyLoaded, InvalidEndOfQuotedStringError @@ -102,11 +102,6 @@ async def message_flusher(): await asyncio.sleep(60) await DBUtils.flush() -async def on_thread_create(bot, thread: Thread): - if bot.user in thread.members: - return - else: - await thread.join() async def on_message(bot, message:Message): if message.author.bot: