Finalize new directory structure
This commit is contained in:
parent
fe3ef1ad35
commit
d83a94c03b
10 changed files with 43 additions and 64 deletions
|
@ -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)
|
||||
|
|
19
jarvis/cogs/extra/__init__.py
Normal file
19
jarvis/cogs/extra/__init__.py
Normal file
|
@ -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)
|
|
@ -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"^(?:(?P<cn>CN=(?P<name>[^,]*)),)?(?:(?P<path>(?:(?:CN|OU)=[^,]+,?)+),)?(?P<domain>(?: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)
|
|
@ -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:
|
|
@ -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")
|
Loading…
Add table
Reference in a new issue