Skip to content

Commit

Permalink
feat: Add shortcut prefixes for prefix ls
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Jul 27, 2023
1 parent e62602d commit dd7c313
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions src/zibot/exts/meta/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
from ...core import commands as cmds
from ...core.context import Context
from ...core.embed import ZEmbed, ZEmbedBuilder
from ...core.errors import DefaultError
from ...core.menus import ZMenuPagesView
from ...utils import utcnow
from ...utils.format import cleanifyPrefix
from ._help import CustomHelp
from ._pages import PrefixesPageSource
from .subcogs import MetaCustomCommands


if TYPE_CHECKING:
from ...core.bot import ziBot

Expand Down Expand Up @@ -78,7 +78,12 @@ def __init__(self, bot: ziBot):
async def source(self, ctx):
await ctx.try_reply(_("source-message", link=self.bot.links["Source Code"]))

@cmds.command(name=_("about"), aliases=("botinfo", "bi"), description=_("about-desc"), hybrid=True)
@cmds.command(
name=_("about"),
aliases=("botinfo", "bi"),
description=_("about-desc"),
hybrid=True,
)
@commands.cooldown(1, 5, commands.BucketType.user)
async def about(self, ctx: Context):
# Z3R0 Banner
Expand All @@ -87,20 +92,29 @@ async def about(self, ctx: Context):
e = ZEmbedBuilder(
description=_(ctx.bot.description + "-extended", license=ctx.bot.license),
)
e.setAuthor(name=ctx.bot.requireUser().name, iconUrl=ctx.bot.requireUser().display_avatar.url)
e.setAuthor(
name=ctx.bot.requireUser().name,
iconUrl=ctx.bot.requireUser().display_avatar.url,
)
e.setImage(url="attachment://banner.png")
e.addField(name=_("about-author-title"), value=ctx.bot.author, inline=True)
e.addField(
name=_("about-library-title"),
value="[`discord.py`](https://github.com/Rapptz/discord.py) - `v{}`".format(discord.__version__),
value="[`discord.py`](https://github.com/Rapptz/discord.py) - `v{}`".format(
discord.__version__
),
inline=True,
)
e.addField(name=_("about-version-title"), value=ctx.bot.version, inline=True)
view = discord.ui.View()
for k, v in ctx.bot.links.items():
if k and v:
view.add_item(discord.ui.Button(label=k, url=v))
await ctx.try_reply(file=f, embed=await e.build(ctx, autoGenerateDT=True, addRequester=True), view=view)
await ctx.try_reply(
file=f,
embed=await e.build(ctx, autoGenerateDT=True, addRequester=True),
view=view,
)

@cmds.command(name=_("stats"), description=_("stats-desc"), hybrid=True)
@commands.cooldown(1, 5, commands.BucketType.user)
Expand All @@ -110,7 +124,9 @@ async def stats(self, ctx: Context):
return
uptime = utcnow() - self.bot.uptime
e = ZEmbedBuilder()
e.setAuthor(name=_("stats-title", bot=botUser.name), iconUrl=botUser.display_avatar.url)
e.setAuthor(
name=_("stats-title", bot=botUser.name), iconUrl=botUser.display_avatar.url
)
e.addField(name=_("stats-uptime-title"), value=humanize.precisedelta(uptime))
e.addField(
name=await ctx.translate(_("stats-command-title")),
Expand All @@ -122,7 +138,19 @@ async def stats(self, ctx: Context):
)
),
)
await ctx.try_reply(embed=await e.build(ctx, autoGenerateDT=True, addRequester=True))
await ctx.try_reply(
embed=await e.build(ctx, autoGenerateDT=True, addRequester=True)
)

@commands.command(
name="prefixes",
description="Shortcut for `prefix ls` command",
invoke_without_command=True,
with_app_command=False,
)
@commands.cooldown(1, 5, commands.BucketType.user)
async def prefixes(self, ctx):
await ctx.try_invoke(self.prefList)

@commands.group(
aliases=("pref",),
Expand All @@ -149,9 +177,15 @@ async def prefix(self, ctx):
exemple=("prefix ls", "pref list"),
)
@commands.cooldown(1, 5, commands.BucketType.user)
async def prefList(self, ctx):
async def prefList(self, ctx: Context):
if not ctx.guild:
raise DefaultError(
"Custom prefix for user is not yet implemented! Ping me to check my default prefixes"
)
prefixes = await ctx.guild.getPrefixes()
menu = ZMenuPagesView(ctx, source=PrefixesPageSource(ctx, ["placeholder"] * 2 + prefixes))
menu = ZMenuPagesView(
ctx, source=PrefixesPageSource(ctx, ["placeholder"] * 2 + prefixes)
)
await menu.start()

@prefix.command(
Expand All @@ -175,7 +209,9 @@ async def prefAdd(self, ctx: Context, *prefix: str):

try:
await ctx.requireGuild().addPrefix(_prefix)
await ctx.success(title=_("prefix-added", prefix=cleanifyPrefix(self.bot, _prefix)))
await ctx.success(
title=_("prefix-added", prefix=cleanifyPrefix(self.bot, _prefix))
)
except Exception as exc:
await ctx.error(str(exc))

Expand All @@ -200,11 +236,15 @@ async def prefRm(self, ctx: Context, *prefix: str):

try:
await ctx.requireGuild().rmPrefix(_prefix.lstrip())
await ctx.success(title=_("prefix-removed", prefix=cleanifyPrefix(self.bot, _prefix)))
await ctx.success(
title=_("prefix-removed", prefix=cleanifyPrefix(self.bot, _prefix))
)
except Exception as exc:
await ctx.error(str(exc))

@cmds.command(name=_("ping"), aliases=("p",), description=_("ping-desc"), hybrid=True)
@cmds.command(
name=_("ping"), aliases=("p",), description=_("ping-desc"), hybrid=True
)
async def ping(self, ctx):
start = time.perf_counter()
msgPing = 0
Expand All @@ -215,7 +255,9 @@ async def ping(self, ctx):

e = ZEmbedBuilder(title=_("ping-title"))

botLatency = f"{round(self.bot.latency*1000)}ms" if not ctx.bot.config.test else "∞"
botLatency = (
f"{round(self.bot.latency*1000)}ms" if not ctx.bot.config.test else "∞"
)

e.addField(
name=_("ping-websocket-title"),
Expand All @@ -228,7 +270,9 @@ async def ping(self, ctx):
value=f"{round(msgPing)}ms",
)

await ctx.try_reply(embed=await e.build(ctx, autoGenerateDT=True, addRequester=True))
await ctx.try_reply(
embed=await e.build(ctx, autoGenerateDT=True, addRequester=True)
)

@cmds.command(name=_("invite"), description=_("invite-desc"), hybrid=True)
async def invite(self, ctx: Context):
Expand Down

0 comments on commit dd7c313

Please sign in to comment.