From 990cfd57b4de409c884ca763446938d40cf9b0c1 Mon Sep 17 00:00:00 2001 From: AstreaTSS <25420078+AstreaTSS@users.noreply.github.com> Date: Sun, 20 Oct 2024 17:32:41 -0400 Subject: [PATCH] feat: add ability to ping on message --- exts/messages/message_admin.py | 40 ++++++++++++++++++- exts/messages/message_cmds.py | 18 ++++++++- .../migration.sql | 2 + schema.prisma | 21 +++++----- 4 files changed, 67 insertions(+), 14 deletions(-) create mode 100755 migrations/20241020212601_ping_for_message/migration.sql diff --git a/exts/messages/message_admin.py b/exts/messages/message_admin.py index aafe7c9..ed6e6bf 100644 --- a/exts/messages/message_admin.py +++ b/exts/messages/message_admin.py @@ -40,8 +40,15 @@ async def messages_info(self, ctx: utils.THIASlashContext) -> None: assert config.messages is not None str_builder = [ - f"Messaging enabled: {utils.toggle_friendly_str(config.messages.enabled)}", - f"Anonymous messaging enabled: {config.messages.anon_enabled}", + f"Messaging enabled: {utils.yesno_friendly_str(config.messages.enabled)}", + ( + "Anonymous messaging enabled:" + f" {utils.yesno_friendly_str(config.messages.anon_enabled)}" + ), + ( + "Pinging on messages:" + f" {utils.yesno_friendly_str(config.messages.ping_for_message)}" + ), "", f"-# Links can be found at {self.message_view_links.mention()}.", ] @@ -109,6 +116,35 @@ async def message_anon_toggle( ) ) + @config.subcommand( + "ping-on-message", + sub_cmd_description="Enables or disables pinging on messages.", + ) + async def message_ping_toggle( + self, + ctx: utils.THIASlashContext, + _toggle: str = tansy.Option( + "Should pinging on messages be turned on or off?", + name="toggle", + choices=[ + ipy.SlashCommandChoice("on", "on"), + ipy.SlashCommandChoice("off", "off"), + ], + ), + ) -> None: + toggle = _toggle == "on" + await ctx.fetch_config({"messages": True}) + + await models.MessageConfig.prisma().update( + data={"ping_for_message": toggle}, where={"guild_id": ctx.guild_id} + ) + + await ctx.send( + embed=utils.make_embed( + f"Pinging on messages turned {utils.toggle_friendly_str(toggle)}!" + ) + ) + @config.subcommand( "help", sub_cmd_description="Tells you how to set up the messaging system." ) diff --git a/exts/messages/message_cmds.py b/exts/messages/message_cmds.py index cdb79b7..a465f01 100644 --- a/exts/messages/message_cmds.py +++ b/exts/messages/message_cmds.py @@ -92,7 +92,14 @@ async def message_whisper( try: other_chan = utils.partial_channel(self.bot, other_user_link.channel_id) - await other_chan.send(embed=embed) + await other_chan.send( + content=( + f"<@{other_user_link.user_id}>" + if config.messages.ping_for_message + else None + ), + embed=embed, + ) except ipy.errors.HTTPException: raise utils.CustomCheckFailure( "Could not send a message to the specified user's channel." @@ -162,7 +169,14 @@ async def message_anon( try: other_chan = utils.partial_channel(self.bot, other_user_link.channel_id) - await other_chan.send(embed=embed) + await other_chan.send( + content=( + f"<@{other_user_link.user_id}>" + if config.messages.ping_for_message + else None + ), + embed=embed, + ) except ipy.errors.HTTPException: raise utils.CustomCheckFailure( "Could not send a message to the specified user's channel." diff --git a/migrations/20241020212601_ping_for_message/migration.sql b/migrations/20241020212601_ping_for_message/migration.sql new file mode 100755 index 0000000..adc4ccc --- /dev/null +++ b/migrations/20241020212601_ping_for_message/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "thiamessageconfig" ADD COLUMN "ping_for_message" BOOLEAN NOT NULL DEFAULT false; diff --git a/schema.prisma b/schema.prisma index 1f0065b..9535712 100644 --- a/schema.prisma +++ b/schema.prisma @@ -114,9 +114,10 @@ model PrismaMessageLink { } model PrismaMessageConfig { - guild_id BigInt @id - enabled Boolean @default(false) - anon_enabled Boolean @default(false) + guild_id BigInt @id + enabled Boolean @default(false) + anon_enabled Boolean @default(false) + ping_for_message Boolean @default(false) links PrismaMessageLink[] main_config PrismaGuildConfig? @relation(fields: [guild_id], references: [guild_id], onDelete: Cascade) @@ -125,11 +126,11 @@ model PrismaMessageConfig { } model PrismaDiceEntry { - id Int @id @default(autoincrement()) - guild_id BigInt - user_id BigInt - name String - value String + id Int @id @default(autoincrement()) + guild_id BigInt + user_id BigInt + name String + value String dice_config PrimsaDiceConfig? @relation(fields: [guild_id], references: [guild_id], onDelete: Cascade) @@ -139,11 +140,11 @@ model PrismaDiceEntry { } model PrimsaDiceConfig { - guild_id BigInt @id + guild_id BigInt @id visible Boolean @default(false) entries PrismaDiceEntry[] - main_config PrismaGuildConfig? @relation(fields: [guild_id], references: [guild_id], onDelete: Cascade) + main_config PrismaGuildConfig? @relation(fields: [guild_id], references: [guild_id], onDelete: Cascade) @@map("thiadiceconfig") }