Skip to content

Commit

Permalink
feat: add ability to ping on message
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS committed Oct 20, 2024
1 parent 8fe6eb3 commit 990cfd5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 14 deletions.
40 changes: 38 additions & 2 deletions exts/messages/message_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.",
]
Expand Down Expand Up @@ -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."
)
Expand Down
18 changes: 16 additions & 2 deletions exts/messages/message_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
Expand Down
2 changes: 2 additions & 0 deletions migrations/20241020212601_ping_for_message/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "thiamessageconfig" ADD COLUMN "ping_for_message" BOOLEAN NOT NULL DEFAULT false;
21 changes: 11 additions & 10 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
}
Expand Down

0 comments on commit 990cfd5

Please sign in to comment.