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."""
|
"""JARVIS Core Cogs."""
|
||||||
from naff import Client
|
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:
|
def setup(bot: Client) -> None:
|
||||||
"""Add core cogs to JARVIS"""
|
"""Add core cogs to JARVIS"""
|
||||||
admin.setup(bot)
|
admin.setup(bot)
|
||||||
botutil.setup(bot)
|
botutil.setup(bot)
|
||||||
|
remindme.setup(bot)
|
||||||
socials.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}
|
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}$")
|
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(
|
URL_VERIFY = re.compile(r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+")
|
||||||
r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
|
|
||||||
)
|
|
||||||
DN_VERIFY = re.compile(
|
DN_VERIFY = re.compile(
|
||||||
r"^(?:(?P<cn>CN=(?P<name>[^,]*)),)?(?:(?P<path>(?:(?:CN|OU)=[^,]+,?)+),)?(?P<domain>(?:DC=[^,]+,?)+)$" # noqa: E501
|
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,
|
opt_type=OptionTypes.STRING,
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(name="attach", description="File to hash", opt_type=OptionTypes.ATTACHMENT, required=False)
|
||||||
name="attach", description="File to hash", opt_type=OptionTypes.ATTACHMENT, required=False
|
|
||||||
)
|
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
||||||
async def _hash(
|
async def _hash(self, ctx: InteractionContext, method: str, data: str = None, attach: Attachment = None) -> None:
|
||||||
self, ctx: InteractionContext, method: str, data: str = None, attach: Attachment = None
|
|
||||||
) -> None:
|
|
||||||
if not data and not attach:
|
if not data and not attach:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"No data to hash",
|
"No data to hash",
|
||||||
|
@ -123,9 +117,7 @@ class DevCog(Extension):
|
||||||
]
|
]
|
||||||
|
|
||||||
embed = build_embed(title=title, description=description, fields=fields)
|
embed = build_embed(title=title, description=description, fields=fields)
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@dev.subcommand(sub_cmd_name="uuid", sub_cmd_description="Generate a UUID")
|
@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_name="uuid2ulid",
|
||||||
sub_cmd_description="Convert a UUID to a ULID",
|
sub_cmd_description="Convert a UUID to a ULID",
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True)
|
||||||
name="uuid", description="UUID to convert", opt_type=OptionTypes.STRING, required=True
|
|
||||||
)
|
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
||||||
async def _uuid2ulid(self, ctx: InteractionContext, uuid: str) -> None:
|
async def _uuid2ulid(self, ctx: InteractionContext, uuid: str) -> None:
|
||||||
if UUID_VERIFY.match(uuid):
|
if UUID_VERIFY.match(uuid):
|
||||||
|
@ -196,9 +186,7 @@ class DevCog(Extension):
|
||||||
sub_cmd_name="ulid2uuid",
|
sub_cmd_name="ulid2uuid",
|
||||||
sub_cmd_description="Convert a ULID to a UUID",
|
sub_cmd_description="Convert a ULID to a UUID",
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True)
|
||||||
name="ulid", description="ULID to convert", opt_type=OptionTypes.STRING, required=True
|
|
||||||
)
|
|
||||||
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
@cooldown(bucket=Buckets.USER, rate=1, interval=2)
|
||||||
async def _ulid2uuid(self, ctx: InteractionContext, ulid: str) -> None:
|
async def _ulid2uuid(self, ctx: InteractionContext, ulid: str) -> None:
|
||||||
if ULID_VERIFY.match(ulid):
|
if ULID_VERIFY.match(ulid):
|
||||||
|
@ -242,9 +230,7 @@ class DevCog(Extension):
|
||||||
EmbedField(name=mstr, value=f"`{encoded}`", inline=False),
|
EmbedField(name=mstr, value=f"`{encoded}`", inline=False),
|
||||||
]
|
]
|
||||||
embed = build_embed(title="Encoded Data", description="", fields=fields)
|
embed = build_embed(title="Encoded Data", description="", fields=fields)
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@dev.subcommand(sub_cmd_name="decode", sub_cmd_description="Decode some data")
|
@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),
|
EmbedField(name=mstr, value=f"`{decoded}`", inline=False),
|
||||||
]
|
]
|
||||||
embed = build_embed(title="Decoded Data", description="", fields=fields)
|
embed = build_embed(title="Decoded Data", description="", fields=fields)
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@dev.subcommand(sub_cmd_name="cloc", sub_cmd_description="Get JARVIS lines of code")
|
@dev.subcommand(sub_cmd_name="cloc", sub_cmd_description="Get JARVIS lines of code")
|
||||||
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
@cooldown(bucket=Buckets.CHANNEL, rate=1, interval=30)
|
||||||
async def _cloc(self, ctx: InteractionContext) -> None:
|
async def _cloc(self, ctx: InteractionContext) -> None:
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
output = subprocess.check_output(["tokei", "-C", "--sort", "code"]).decode(
|
output = subprocess.check_output(["tokei", "-C", "--sort", "code"]).decode("UTF-8") # noqa: S603, S607
|
||||||
"UTF-8"
|
|
||||||
) # noqa: S603, S607
|
|
||||||
console = Console()
|
console = Console()
|
||||||
with console.capture() as capture:
|
with console.capture() as capture:
|
||||||
console.print(output)
|
console.print(output)
|
|
@ -75,9 +75,7 @@ class ImageCog(Extension):
|
||||||
|
|
||||||
tgt = self.tgt_match.match(target)
|
tgt = self.tgt_match.match(target)
|
||||||
if not tgt:
|
if not tgt:
|
||||||
await ctx.send(
|
await ctx.send(f"Invalid target format ({target}). Expected format like 200KB", ephemeral=True)
|
||||||
f"Invalid target format ({target}). Expected format like 200KB", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -151,12 +149,8 @@ class ImageCog(Extension):
|
||||||
]
|
]
|
||||||
embed = build_embed(title=filename, description="", fields=fields)
|
embed = build_embed(title=filename, description="", fields=fields)
|
||||||
embed.set_image(url="attachment://resized.png")
|
embed.set_image(url="attachment://resized.png")
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
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)
|
||||||
)
|
|
||||||
await ctx.send(
|
|
||||||
embeds=embed, file=File(file=bufio, file_name="resized.png"), components=components
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: Client) -> None:
|
def setup(bot: Client) -> None:
|
|
@ -45,9 +45,7 @@ class TagCog(Extension):
|
||||||
async def _get(self, ctx: InteractionContext, name: str) -> None:
|
async def _get(self, ctx: InteractionContext, name: str) -> None:
|
||||||
tag = await Tag.find_one(q(guild=ctx.guild.id, name=name))
|
tag = await Tag.find_one(q(guild=ctx.guild.id, name=name))
|
||||||
if not tag:
|
if not tag:
|
||||||
await ctx.send(
|
await ctx.send("Well this is awkward, looks like the tag was deleted just now", ephemeral=True)
|
||||||
"Well this is awkward, looks like the tag was deleted just now", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
await ctx.send(tag.content)
|
await ctx.send(tag.content)
|
||||||
|
@ -92,9 +90,7 @@ class TagCog(Extension):
|
||||||
or ctx.author.has_permission(Permissions.MANAGE_MESSAGES)
|
or ctx.author.has_permission(Permissions.MANAGE_MESSAGES)
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
await response.send(
|
await response.send("Listen, don't use this to try and bypass the rules", ephemeral=True)
|
||||||
"Listen, don't use this to try and bypass the rules", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
elif not content.strip() or not name.strip():
|
elif not content.strip() or not name.strip():
|
||||||
await response.send("Content and name required", ephemeral=True)
|
await response.send("Content and name required", ephemeral=True)
|
||||||
|
@ -129,9 +125,7 @@ class TagCog(Extension):
|
||||||
icon_url=ctx.author.display_avatar.url,
|
icon_url=ctx.author.display_avatar.url,
|
||||||
)
|
)
|
||||||
|
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
|
|
||||||
await response.send(embeds=embed, components=components)
|
await response.send(embeds=embed, components=components)
|
||||||
if ctx.guild.id not in self.cache:
|
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))
|
new_tag = await Tag.find_one(q(guild=ctx.guild.id, name=name))
|
||||||
if new_tag and new_tag.id != tag.id:
|
if new_tag and new_tag.id != tag.id:
|
||||||
await ctx.send(
|
await ctx.send("That tag name is used by another tag, choose another name", ephemeral=True)
|
||||||
"That tag name is used by another tag, choose another name", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
noinvite = await Setting.find_one(q(guild=ctx.guild.id, setting="noinvite"))
|
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)
|
or ctx.author.has_permission(Permissions.MANAGE_MESSAGES)
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
await response.send(
|
await response.send("Listen, don't use this to try and bypass the rules", ephemeral=True)
|
||||||
"Listen, don't use this to try and bypass the rules", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
elif not content.strip() or not name.strip():
|
elif not content.strip() or not name.strip():
|
||||||
await response.send("Content and name required", ephemeral=True)
|
await response.send("Content and name required", ephemeral=True)
|
||||||
|
@ -235,9 +225,7 @@ class TagCog(Extension):
|
||||||
name=ctx.author.username + "#" + ctx.author.discriminator,
|
name=ctx.author.username + "#" + ctx.author.discriminator,
|
||||||
icon_url=ctx.author.display_avatar.url,
|
icon_url=ctx.author.display_avatar.url,
|
||||||
)
|
)
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await response.send(embeds=embed, components=components)
|
await response.send(embeds=embed, components=components)
|
||||||
if tag.name not in self.cache[ctx.guild.id]:
|
if tag.name not in self.cache[ctx.guild.id]:
|
||||||
self.cache[ctx.guild.id].remove(old_name)
|
self.cache[ctx.guild.id].remove(old_name)
|
||||||
|
@ -260,9 +248,7 @@ class TagCog(Extension):
|
||||||
ctx.author.has_permission(Permissions.ADMINISTRATOR)
|
ctx.author.has_permission(Permissions.ADMINISTRATOR)
|
||||||
or ctx.author.has_permission(Permissions.MANAGE_MESSAGES)
|
or ctx.author.has_permission(Permissions.MANAGE_MESSAGES)
|
||||||
):
|
):
|
||||||
await ctx.send(
|
await ctx.send("You didn't create this tag, ask the creator to delete it", ephemeral=True)
|
||||||
"You didn't create this tag, ask the creator to delete it", ephemeral=True
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
await tag.delete()
|
await tag.delete()
|
||||||
|
@ -316,9 +302,7 @@ class TagCog(Extension):
|
||||||
name=f"{username}#{discrim}" if username else "Unknown User",
|
name=f"{username}#{discrim}" if username else "Unknown User",
|
||||||
icon_url=url,
|
icon_url=url,
|
||||||
)
|
)
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@tag.subcommand(sub_cmd_name="list", sub_cmd_description="List tag names")
|
@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)
|
tags = await Tag.find(q(guild=ctx.guild.id)).to_list(None)
|
||||||
names = "\n".join(f"`{t.name}`" for t in tags)
|
names = "\n".join(f"`{t.name}`" for t in tags)
|
||||||
embed = build_embed(title="All Tags", description=names, fields=[])
|
embed = build_embed(title="All Tags", description=names, fields=[])
|
||||||
components = Button(
|
components = Button(style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}")
|
||||||
style=ButtonStyles.DANGER, emoji="🗑️", custom_id=f"delete|{ctx.author.id}"
|
|
||||||
)
|
|
||||||
await ctx.send(embeds=embed, components=components)
|
await ctx.send(embeds=embed, components=components)
|
||||||
|
|
||||||
@_get.autocomplete("name")
|
@_get.autocomplete("name")
|
Loading…
Add table
Reference in a new issue