diff --git a/jarvis/cogs/core/__init__.py b/jarvis/cogs/core/__init__.py index bfc4e38..629742a 100644 --- a/jarvis/cogs/core/__init__.py +++ b/jarvis/cogs/core/__init__.py @@ -1,11 +1,13 @@ """JARVIS Core Cogs.""" from naff import Client -from jarvis.cogs.core import admin, botutil, socials +from jarvis.cogs.core import admin, botutil, remindme, socials, util def setup(bot: Client) -> None: """Add core cogs to JARVIS""" admin.setup(bot) botutil.setup(bot) + remindme.setup(bot) socials.setup(bot) + util.setup(bot) diff --git a/jarvis/cogs/remindme.py b/jarvis/cogs/core/remindme.py similarity index 100% rename from jarvis/cogs/remindme.py rename to jarvis/cogs/core/remindme.py diff --git a/jarvis/cogs/util.py b/jarvis/cogs/core/util.py similarity index 100% rename from jarvis/cogs/util.py rename to jarvis/cogs/core/util.py diff --git a/jarvis/cogs/extra/__init__.py b/jarvis/cogs/extra/__init__.py new file mode 100644 index 0000000..9067b99 --- /dev/null +++ b/jarvis/cogs/extra/__init__.py @@ -0,0 +1,19 @@ +"""JARVIS extra, optional cogs""" +from naff import Client + +from jarvis.cogs.extra import calc, dev, image, pinboard, rolegiver, tags + + +def setup(bot: Client) -> None: + """ + Add extra cogs to JARVIS + + TODO: load which cogs are subscribed to where and dynamically register them + to only the guilds that are subscribed to them. + """ + calc.setup(bot) + dev.setup(bot) + image.setup(bot) + pinboard.setup(bot) + rolegiver.setup(bot) + tags.setup(bot) diff --git a/jarvis/cogs/calc.py b/jarvis/cogs/extra/calc.py similarity index 100% rename from jarvis/cogs/calc.py rename to jarvis/cogs/extra/calc.py diff --git a/jarvis/cogs/dev.py b/jarvis/cogs/extra/dev.py similarity index 90% rename from jarvis/cogs/dev.py rename to jarvis/cogs/extra/dev.py index 1718805..3add3a6 100644 --- a/jarvis/cogs/dev.py +++ b/jarvis/cogs/extra/dev.py @@ -36,9 +36,7 @@ from jarvis.utils import build_embed supported_hashes = {x for x in hashlib.algorithms_guaranteed if "shake" not in x} OID_VERIFY = re.compile(r"^([1-9][0-9]{0,3}|0)(\.([1-9][0-9]{0,3}|0)){5,13}$") -URL_VERIFY = re.compile( - r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" -) +URL_VERIFY = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+") DN_VERIFY = re.compile( r"^(?:(?PCN=(?P[^,]*)),)?(?:(?P(?:(?:CN|OU)=[^,]+,?)+),)?(?P(?:DC=[^,]+,?)+)$" # noqa: E501 ) @@ -76,13 +74,9 @@ class DevCog(Extension): opt_type=OptionTypes.STRING, required=False, ) - @slash_option( - name="attach", description="File to hash", opt_type=OptionTypes.ATTACHMENT, required=False - ) + @slash_option(name="attach", description="File to hash", opt_type=OptionTypes.ATTACHMENT, required=False) @cooldown(bucket=Buckets.USER, rate=1, interval=2) - async def _hash( - self, ctx: InteractionContext, method: str, data: str = None, attach: Attachment = None - ) -> None: + async def _hash(self, ctx: InteractionContext, method: str, data: str = None, attach: Attachment = None) -> None: if not data and not attach: await ctx.send( "No data to hash", @@ -123,9 +117,7 @@ class DevCog(Extension): ] embed = build_embed(title=title, description=description, fields=fields) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await ctx.send(embeds=embed, components=components) @dev.subcommand(sub_cmd_name="uuid", sub_cmd_description="Generate a UUID") @@ -181,9 +173,7 @@ class DevCog(Extension): sub_cmd_name="uuid2ulid", sub_cmd_description="Convert a UUID to a ULID", ) - @slash_option( - name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True - ) + @slash_option(name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True) @cooldown(bucket=Buckets.USER, rate=1, interval=2) async def _uuid2ulid(self, ctx: InteractionContext, uuid: str) -> None: if UUID_VERIFY.match(uuid): @@ -196,9 +186,7 @@ class DevCog(Extension): sub_cmd_name="ulid2uuid", sub_cmd_description="Convert a ULID to a UUID", ) - @slash_option( - name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True - ) + @slash_option(name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True) @cooldown(bucket=Buckets.USER, rate=1, interval=2) async def _ulid2uuid(self, ctx: InteractionContext, ulid: str) -> None: if ULID_VERIFY.match(ulid): @@ -242,9 +230,7 @@ class DevCog(Extension): EmbedField(name=mstr, value=f"`{encoded}`", inline=False), ] embed = build_embed(title="Encoded Data", description="", fields=fields) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await ctx.send(embeds=embed, components=components) @dev.subcommand(sub_cmd_name="decode", sub_cmd_description="Decode some data") @@ -280,18 +266,14 @@ class DevCog(Extension): EmbedField(name=mstr, value=f"`{decoded}`", inline=False), ] embed = build_embed(title="Decoded Data", description="", fields=fields) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await ctx.send(embeds=embed, components=components) @dev.subcommand(sub_cmd_name="cloc", sub_cmd_description="Get JARVIS lines of code") @cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30) async def _cloc(self, ctx: InteractionContext) -> None: await ctx.defer() - output = subprocess.check_output(["tokei", "-C", "--sort", "code"]).decode( - "UTF-8" - ) # noqa: S603, S607 + output = subprocess.check_output(["tokei", "-C", "--sort", "code"]).decode("UTF-8") # noqa: S603, S607 console = Console() with console.capture() as capture: console.print(output) diff --git a/jarvis/cogs/image.py b/jarvis/cogs/extra/image.py similarity index 92% rename from jarvis/cogs/image.py rename to jarvis/cogs/extra/image.py index 83e385b..8e34eff 100644 --- a/jarvis/cogs/image.py +++ b/jarvis/cogs/extra/image.py @@ -75,9 +75,7 @@ class ImageCog(Extension): tgt = self.tgt_match.match(target) if not tgt: - await ctx.send( - f"Invalid target format ({target}). Expected format like 200KB", ephemeral=True - ) + await ctx.send(f"Invalid target format ({target}). Expected format like 200KB", ephemeral=True) return try: @@ -151,12 +149,8 @@ class ImageCog(Extension): ] embed = build_embed(title=filename, description="", fields=fields) embed.set_image(url="attachment://resized.png") - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) - await ctx.send( - embeds=embed, file=File(file=bufio, file_name="resized.png"), components=components - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") + await ctx.send(embeds=embed, file=File(file=bufio, file_name="resized.png"), components=components) def setup(bot: Client) -> None: diff --git a/jarvis/cogs/starboard.py b/jarvis/cogs/extra/pinboard.py similarity index 100% rename from jarvis/cogs/starboard.py rename to jarvis/cogs/extra/pinboard.py diff --git a/jarvis/cogs/rolegiver.py b/jarvis/cogs/extra/rolegiver.py similarity index 100% rename from jarvis/cogs/rolegiver.py rename to jarvis/cogs/extra/rolegiver.py diff --git a/jarvis/cogs/tags.py b/jarvis/cogs/extra/tags.py similarity index 90% rename from jarvis/cogs/tags.py rename to jarvis/cogs/extra/tags.py index a06e2ef..d6b53e8 100644 --- a/jarvis/cogs/tags.py +++ b/jarvis/cogs/extra/tags.py @@ -45,9 +45,7 @@ class TagCog(Extension): async def _get(self, ctx: InteractionContext, name: str) -> None: tag = await Tag.find_one(q(guild=ctx.guild.id, name=name)) if not tag: - await ctx.send( - "Well this is awkward, looks like the tag was deleted just now", ephemeral=True - ) + await ctx.send("Well this is awkward, looks like the tag was deleted just now", ephemeral=True) return await ctx.send(tag.content) @@ -92,9 +90,7 @@ class TagCog(Extension): or ctx.author.has_permission(Permissions.MANAGE_MESSAGES) ) ): - await response.send( - "Listen, don't use this to try and bypass the rules", ephemeral=True - ) + await response.send("Listen, don't use this to try and bypass the rules", ephemeral=True) return elif not content.strip() or not name.strip(): await response.send("Content and name required", ephemeral=True) @@ -129,9 +125,7 @@ class TagCog(Extension): icon_url=ctx.author.display_avatar.url, ) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await response.send(embeds=embed, components=components) if ctx.guild.id not in self.cache: @@ -189,9 +183,7 @@ class TagCog(Extension): new_tag = await Tag.find_one(q(guild=ctx.guild.id, name=name)) if new_tag and new_tag.id != tag.id: - await ctx.send( - "That tag name is used by another tag, choose another name", ephemeral=True - ) + await ctx.send("That tag name is used by another tag, choose another name", ephemeral=True) return noinvite = await Setting.find_one(q(guild=ctx.guild.id, setting="noinvite")) @@ -204,9 +196,7 @@ class TagCog(Extension): or ctx.author.has_permission(Permissions.MANAGE_MESSAGES) ) ): - await response.send( - "Listen, don't use this to try and bypass the rules", ephemeral=True - ) + await response.send("Listen, don't use this to try and bypass the rules", ephemeral=True) return elif not content.strip() or not name.strip(): await response.send("Content and name required", ephemeral=True) @@ -235,9 +225,7 @@ class TagCog(Extension): name=ctx.author.username + "#" + ctx.author.discriminator, icon_url=ctx.author.display_avatar.url, ) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await response.send(embeds=embed, components=components) if tag.name not in self.cache[ctx.guild.id]: self.cache[ctx.guild.id].remove(old_name) @@ -260,9 +248,7 @@ class TagCog(Extension): ctx.author.has_permission(Permissions.ADMINISTRATOR) or ctx.author.has_permission(Permissions.MANAGE_MESSAGES) ): - await ctx.send( - "You didn't create this tag, ask the creator to delete it", ephemeral=True - ) + await ctx.send("You didn't create this tag, ask the creator to delete it", ephemeral=True) return await tag.delete() @@ -316,9 +302,7 @@ class TagCog(Extension): name=f"{username}#{discrim}" if username else "Unknown User", icon_url=url, ) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await ctx.send(embeds=embed, components=components) @tag.subcommand(sub_cmd_name="list", sub_cmd_description="List tag names") @@ -326,9 +310,7 @@ class TagCog(Extension): tags = await Tag.find(q(guild=ctx.guild.id)).to_list(None) names = "\n".join(f"`{t.name}`" for t in tags) embed = build_embed(title="All Tags", description=names, fields=[]) - components = Button( - style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}" - ) + components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}") await ctx.send(embeds=embed, components=components) @_get.autocomplete("name")