From 8aec106671afba4d41d104369d705e73016b5733 Mon Sep 17 00:00:00 2001 From: Vegard Berg Date: Sat, 15 Oct 2022 02:51:21 +0200 Subject: [PATCH] Changed directory structure --- Heimdallr.py => heimdallr/Heimdallr.py | 14 ++++---- {commands => heimdallr/commands}/admin.py | 0 .../commands}/bot_messages.py | 0 {commands => heimdallr/commands}/gatekeep.py | 0 .../commands}/infractions.py | 34 +++++++++++++------ {commands => heimdallr/commands}/polls.py | 2 +- {commands => heimdallr/commands}/quote.py | 0 .../commands}/self_roles.py | 0 pyproject.toml | 3 ++ run.sh | 2 +- 10 files changed, 36 insertions(+), 19 deletions(-) rename Heimdallr.py => heimdallr/Heimdallr.py (91%) rename {commands => heimdallr/commands}/admin.py (100%) rename {commands => heimdallr/commands}/bot_messages.py (100%) rename {commands => heimdallr/commands}/gatekeep.py (100%) rename {commands => heimdallr/commands}/infractions.py (89%) rename {commands => heimdallr/commands}/polls.py (99%) rename {commands => heimdallr/commands}/quote.py (100%) rename {commands => heimdallr/commands}/self_roles.py (100%) diff --git a/Heimdallr.py b/heimdallr/Heimdallr.py similarity index 91% rename from Heimdallr.py rename to heimdallr/Heimdallr.py index 35251a5..6a77fd9 100644 --- a/Heimdallr.py +++ b/heimdallr/Heimdallr.py @@ -157,13 +157,13 @@ def main(): JoinLeave.create_table() # Load extensions - bot.load_extension("commands.admin") - bot.load_extension("commands.gatekeep") - bot.load_extension("commands.quote") - bot.load_extension("commands.infractions") - bot.load_extension("commands.self_roles") - bot.load_extension("commands.polls") - bot.load_extension("commands.bot_messages") + bot.load_extension("heimdallr.commands.admin") + bot.load_extension("heimdallr.commands.gatekeep") + bot.load_extension("heimdallr.commands.quote") + bot.load_extension("heimdallr.commands.infractions") + bot.load_extension("heimdallr.commands.self_roles") + bot.load_extension("heimdallr.commands.polls") + bot.load_extension("heimdallr.commands.bot_messages") bot.start(getenv("DISCORD_TOKEN")) if __name__ == "__main__": diff --git a/commands/admin.py b/heimdallr/commands/admin.py similarity index 100% rename from commands/admin.py rename to heimdallr/commands/admin.py diff --git a/commands/bot_messages.py b/heimdallr/commands/bot_messages.py similarity index 100% rename from commands/bot_messages.py rename to heimdallr/commands/bot_messages.py diff --git a/commands/gatekeep.py b/heimdallr/commands/gatekeep.py similarity index 100% rename from commands/gatekeep.py rename to heimdallr/commands/gatekeep.py diff --git a/commands/infractions.py b/heimdallr/commands/infractions.py similarity index 89% rename from commands/infractions.py rename to heimdallr/commands/infractions.py index 83c2985..137e93f 100644 --- a/commands/infractions.py +++ b/heimdallr/commands/infractions.py @@ -15,6 +15,7 @@ from naff import ( Button, ButtonStyles, ) +from naff.ext.paginators import Paginator from peewee import fn from database import ( GuildSettings, @@ -59,7 +60,10 @@ class Infractions(Extension): ) embeds.append(embed) - await ctx.send(embed=embeds, ephemeral=True) + # await ctx.send(embed=embeds, ephemeral=True) + paginator = Paginator.create_from_embeds(self.client, *embeds) + await paginator.send(ctx) + paginator.send @slash_command( name="user-infractions", @@ -121,13 +125,23 @@ class Infractions(Extension): ) embeds.append(embed) - await ctx.send( - content=f"{user.mention} has {infractions_weight[0].total_infractions} infractions, for a total weight of {infractions_weight[0].total_weight:.2f}" - if infractions_weight.count() > 0 - else None, - embed=embeds, - ephemeral=False, - ) + if len(embeds) <= 10: + await ctx.send( + content=f"{user.mention} has {infractions_weight[0].total_infractions} infractions, for a total weight of {infractions_weight[0].total_weight:.2f}" + if infractions_weight.count() > 0 + else None, + embed=embeds, + ephemeral=False, + ) + else: + await ctx.send( + content=f"{user.mention} has {infractions_weight[0].total_infractions} infractions, for a total weight of {infractions_weight[0].total_weight:.2f}" + if infractions_weight.count() > 0 + else None, + embed=embeds[:10], + ephemeral=False, + ) + await ctx.send(embed=embeds[10:]) @slash_command( name="warn", @@ -209,7 +223,6 @@ class Infractions(Extension): ephemeral=True, ) - # TODO: Add this in again when GuildSettings is implemented guild_settings: Optional[GuildSettings] = GuildSettings.get_or_none(GuildSettings.guild_id == int(ctx.guild_id)) if guild_settings is not None: @@ -271,6 +284,7 @@ class Infractions(Extension): ) ] + given_by: Member = await self.client.fetch_member(f"{infraction.given_by}", ctx.guild_id) await ctx.send( content="Remove this infraction? (times out in 60 seconds)", embed=Embed( @@ -284,7 +298,7 @@ class Infractions(Extension): value=f"", ), EmbedField(name="**Severity**", value=f"{infraction.weight}"), - EmbedField(name="**Issued by**", value=f"{infraction.given_by}"), + EmbedField(name="**Issued by**", value=f"{given_by.display_name} ({given_by.username}#{given_by.discriminator})"), ], ), ephemeral=True, diff --git a/commands/polls.py b/heimdallr/commands/polls.py similarity index 99% rename from commands/polls.py rename to heimdallr/commands/polls.py index f1bad19..eb947bb 100644 --- a/commands/polls.py +++ b/heimdallr/commands/polls.py @@ -309,7 +309,6 @@ class Polls(Extension): @listen(events.Button) async def on_button(self, button: events.Button): ctx = button.context - await ctx.defer(ephemeral=True) # Ensure that the pressed button is a vote button. if ctx.custom_id.startswith("poll-vote:"): @@ -325,6 +324,7 @@ class Polls(Extension): if poll_entry.expires and datetime.now() > poll_entry.expires: return + await ctx.defer(ephemeral=True) if not poll_entry.multiple_choice: votes_q: List[PollVotesModel] = PollVotesModel.select().where( PollVotesModel.poll_id == poll_id, diff --git a/commands/quote.py b/heimdallr/commands/quote.py similarity index 100% rename from commands/quote.py rename to heimdallr/commands/quote.py diff --git a/commands/self_roles.py b/heimdallr/commands/self_roles.py similarity index 100% rename from commands/self_roles.py rename to heimdallr/commands/self_roles.py diff --git a/pyproject.toml b/pyproject.toml index c9f8bec..26af7ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,9 @@ version = "0.1.0" description = "A moderation and general-purpose Discord bot, originally intended for the Norwegian Language Learning community." authors = ["Vegard Berg "] +[tool.poetry.scripts] +heimdallr = "heimdallr.Heimdallr:main" + [tool.poetry.dependencies] python = "^3.10" peewee = "^3.15.1" diff --git a/run.sh b/run.sh index 98819fa..b344ad7 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #! /bin/sh if command -v poetry > /dev/null; then - poetry install -q && poetry run python Heimdallr.py + poetry install -q && poetry run python heimdallr/Heimdallr.py else echo "Poetry must be installed and available in the PATH" >&2 fi \ No newline at end of file