Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md

Large diffs are not rendered by default.

66 changes: 34 additions & 32 deletions cogs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,62 +41,64 @@ async def settings(self, i: discore.Interaction):
async def about(self, i: discore.Interaction):
entrypoint_context.set(f"command about {{interaction={i!r}}}")
await Event.buff_cr({'name': 'command_about'})
embed = discore.Embed(
title=t('about.name'),
description=t('about.description'))
discore.set_embed_footer(self.bot, embed)
embed.add_field(
name=t('about.help.name'),
value=t('about.help.value',
settings_command='/' + t('settings.command.name'),
support_link=discore.config.support_link,
troubleshooting_section=t('settings.troubleshooting.name')),
inline=False
)
embed.add_field(
name=t('about.premium.name'),
value=t(f'about.premium.{str(bool(is_premium(i))).lower()}'),
inline=False)
embed.add_field(
name=t('about.links.name'),
value=t('about.links.value',
invite_link=discore.config.invite_link.format(id=self.bot.application_id),
topgg_link=discore.config.topgg_link.format(id=self.bot.user.id),
repo_link=discore.config.repo_link,
translation_link=discore.config.translation_link,
credits_link=discore.config.repo_link + "/blob/v" + discore.config.version + "/README.md#credits",
support_link=discore.config.support_link),
inline=False)
view = discore.ui.View()
links = discore.ui.ActionRow()
if not is_premium(i) and is_sku():
view.add_item(discore.ui.Button(
links.add_item(discore.ui.Button(
style=discore.ButtonStyle.premium,
sku_id=discore.config.sku
))
view.add_item(discore.ui.Button(
links.add_item(discore.ui.Button(
style=discore.ButtonStyle.link,
label=t('about.source'),
url=discore.config.repo_link,
emoji=discore.PartialEmoji.from_str(discore.config.emoji.github)
))
view.add_item(discore.ui.Button(
links.add_item(discore.ui.Button(
style=discore.ButtonStyle.link,
label=t('about.invite'),
url=discore.config.invite_link.format(id=self.bot.application_id),
emoji=discore.PartialEmoji.from_str(discore.config.emoji.add)
))
view.add_item(discore.ui.Button(
links.add_item(discore.ui.Button(
style=discore.ButtonStyle.link,
label=t('about.support'),
url=discore.config.support_link,
emoji=discore.PartialEmoji.from_str(discore.config.emoji.discord)
))
view = discore.ui.LayoutView()
view.add_item(discore.ui.Container(
discore.ui.Section(
f"## {t('about.name')}\n{t('about.description')}",
accessory=discore.ui.Thumbnail(self.bot.user.display_avatar.url)),
discore.ui.Separator(),
discore.ui.TextDisplay(
f"### {t('about.help.name')}\n" + t(
'about.help.value',
settings_command='/' + t('settings.command.name'),
support_link=discore.config.support_link,
troubleshooting_section=t('settings.troubleshooting.name'))),
discore.ui.TextDisplay(
f"### {t('about.premium.name')}\n" + t(f'about.premium.{str(bool(is_premium(i))).lower()}')),
discore.ui.TextDisplay(
f"### {t('about.links.name')}\n" + t(
'about.links.value',
invite_link=discore.config.invite_link.format(id=self.bot.application_id),
topgg_link=discore.config.topgg_link.format(id=self.bot.user.id),
repo_link=discore.config.repo_link,
translation_link=discore.config.translation_link,
credits_link=discore.config.repo_link + "/blob/v" + discore.config.version + "/README.md#credits",
support_link=discore.config.support_link)),
discore.ui.Separator(),
links,
discore.ui.TextDisplay(footer(self.bot)),
accent_color=discore.config.color or None
))

# Discord API sometimes returns incorrect error code, in this case 404 Unknown interaction when interaction
# is actually found and the message has been sent.
# Even if the interaction is really not found, there's not much we can do (as the interaction is lost),
# so in both cases we just ignore the error.
try:
await i.response.send_message(embed=embed, view=view)
await i.response.send_message(view=view, allowed_mentions=discore.AllowedMentions.none())
except discore.NotFound:
pass
116 changes: 46 additions & 70 deletions cogs/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Developer(discore.Cog,
@discore.app_commands.guilds(*dev_guilds)
async def update(self, i: discore.Interaction) -> None:
await i.response.defer(thinking=True)
await i.followup.send(execute_command("git pull"))
await i.edit_original_response(view=utils.notice(execute_command("git pull")))

@discore.app_commands.command(
name="requirements",
Expand All @@ -65,7 +65,8 @@ async def update(self, i: discore.Interaction) -> None:
@discore.app_commands.guilds(*dev_guilds)
async def requirements(self, i: discore.Interaction) -> None:
await i.response.defer(thinking=True)
await i.followup.send(execute_command("pip install --force-reinstall -r requirements.txt", timeout=120))
await i.edit_original_response(
view=utils.notice(execute_command("pip install --force-reinstall -r requirements.txt", timeout=120)))

@discore.app_commands.command(
name="shell",
Expand All @@ -74,7 +75,7 @@ async def requirements(self, i: discore.Interaction) -> None:
@discore.app_commands.guilds(*dev_guilds)
async def shell(self, i: discore.Interaction, command: str, timeout: int | None = 30) -> None:
await i.response.defer(thinking=True)
await i.followup.send(execute_command(command, timeout=timeout))
await i.edit_original_response(view=utils.notice(execute_command(command, timeout=timeout)))

@discore.app_commands.command(
name="exec",
Expand All @@ -98,10 +99,10 @@ async def _exec(self, i: discore.Interaction, code: str) -> None:
exec(function, env)
res = repr(await env["_ex"](self, i))
except Exception as e:
await i.followup.send(f"```{type(e).__name__}: {e}```")
await i.edit_original_response(view=utils.notice(f"```{type(e).__name__}: {e}```"))
return
await i.followup.send(
f"```py\n{discore.sanitize(res, limit=1990)}\n```")
await i.edit_original_response(
view=utils.notice(f"```py\n{discore.sanitize(res, limit=1990)}\n```"))

@discore.app_commands.command(
name="log",
Expand All @@ -112,7 +113,7 @@ async def log(self, i: discore.Interaction) -> None:
with open(discore.config.log.file, encoding='utf-8') as f:
logs = f.read()
await i.response.send_message(
f"```\n{discore.sanitize(logs, 1992, replace_newline=False, crop_at_end=False)}\n```")
view=utils.notice(f"```\n{discore.sanitize(logs, 1992, replace_newline=False, crop_at_end=False)}\n```"))

@discore.app_commands.command(
name="runtime",
Expand All @@ -137,64 +138,38 @@ async def runtime(self, i: discore.Interaction) -> None:
except asyncio.TimeoutError:
pass

e = discore.Embed(
title="Runtime",
color=discore.config.color or None)
e.add_field(
name="Bot Version",
value=discore.config.version)
e.add_field(
name="Bot commit",
value='`' + subprocess.check_output('git log -1 --pretty=format:"%h"', shell=True, encoding='utf-8') + '`')
e.add_field(
name="Bot commit date",
value="<t:" + subprocess.check_output(
'git log -1 --pretty=format:"%ct"', shell=True, encoding='utf-8') + ":f>")
e.add_field(
name="Discore Version",
value=metadata.version('discore'))
e.add_field(
name="Discore commit",
value=f"`{discore_commit[:7]}`")
e.add_field(
name="Discore commit date",
value=f"<t:{int(commit_date)}:f>" if commit_date else "Unknown")
e.add_field(
name="Discord.py Version",
value=metadata.version('discord.py'))
e.add_field(
name="Python Version",
value='.'.join(map(str, sys.version_info[:3])))
e.add_field(
name="Platform",
value=sys.platform)
e.add_field(
name="Start time",
value=f"<t:{int(self.bot.start_time.timestamp())}:f>"
if self.bot.start_time
else f"<t:{int(self.bot.initialisation_time.timestamp())}:f> (init)")
e.add_field(
name="Uptime",
value=f"<t:{int(self.bot.start_time.timestamp())}:R>"
if self.bot.start_time
else f"<t:{int(self.bot.initialisation_time.timestamp())}:R> (init)")
e.add_field(
name="Current time",
value=f"<t:{int(datetime.datetime.now().timestamp())}:f>")
e.add_field(
name="Memory usage",
value=f"{p.memory_info().rss / 1024 / 1024:.2f} MB")
e.add_field(
name="CPU usage",
value=f"{p.cpu_percent():.2f} %")
e.set_footer(
text=self.bot.user.name + (
f" | ver. {discore.config.version}" if discore.config.version else ""),
icon_url=self.bot.user.display_avatar.url
)
discore.set_embed_footer(self.bot, e)

await i.response.send_message(embed=e)
fields = {
"Bot Version": discore.config.version,
"Bot commit":
'`' + subprocess.check_output('git log -1 --pretty=format:"%h"', shell=True, encoding='utf-8') + '`',
"Bot commit date":
"<t:" + subprocess.check_output('git log -1 --pretty=format:"%ct"', shell=True, encoding='utf-8') + ":f>",
"Discore Version": metadata.version('discore'),
"Discore commit": f"`{discore_commit[:7]}`",
"Discore commit date": f"<t:{int(commit_date)}:f>" if commit_date else "Unknown",
"Discord.py Version": metadata.version('discord.py'),
"Python Version": '.'.join(map(str, sys.version_info[:3])),
"Platform": sys.platform,
"Start time":
f"<t:{int(self.bot.start_time.timestamp())}:f>"
if self.bot.start_time
else f"<t:{int(self.bot.initialisation_time.timestamp())}:f> (init)",
"Uptime":
f"<t:{int(self.bot.start_time.timestamp())}:R>"
if self.bot.start_time
else f"<t:{int(self.bot.initialisation_time.timestamp())}:R> (init)",
"Current time": f"<t:{int(datetime.datetime.now().timestamp())}:f>",
"Memory usage": f"{p.memory_info().rss / 1024 / 1024:.2f} MB",
"CPU usage": f"{p.cpu_percent():.2f} %",
}
view = discore.ui.LayoutView()
view.add_item(discore.ui.Container(
discore.ui.TextDisplay("## Runtime\n" + "\n".join(f"**{name}:** {value}" for name, value in fields.items())),
discore.ui.TextDisplay(utils.footer(self.bot)),
accent_color=discore.config.color or None
))

await i.response.send_message(view=view)


@discore.app_commands.command(
Expand All @@ -204,11 +179,11 @@ async def runtime(self, i: discore.Interaction) -> None:
@discore.app_commands.guilds(*dev_guilds)
async def add_premium(self, i: discore.Interaction) -> None:
if not discore.config.sku:
await i.response.send_message("SKU not set")
await i.response.send_message(view=utils.notice("SKU not set"))
return
await self.bot.create_entitlement(
sku=discore.Object(id=discore.config.sku), owner=i.guild, owner_type=discore.EntitlementOwnerType.guild)
await i.response.send_message("Premium enabled")
await i.response.send_message(view=utils.notice("Premium enabled"))

@discore.app_commands.command(
name="remove_premium",
Expand All @@ -217,12 +192,13 @@ async def add_premium(self, i: discore.Interaction) -> None:
@discore.app_commands.guilds(*dev_guilds)
async def remove_premium(self, i: discore.Interaction) -> None:
if not discore.config.sku:
await i.response.send_message("SKU not set")
await i.response.send_message(view=utils.notice("SKU not set"))
return
for entitlement in i.entitlements:
if entitlement.sku_id == discore.config.sku:
try:
await entitlement.delete()
except:
await i.response.send_message("Failed to disable premium")
await i.response.send_message("Premium disabled")
await i.response.send_message(view=utils.notice("Failed to disable premium"))
return
await i.response.send_message(view=utils.notice("Premium disabled"))
Loading
Loading