Skip to content

Commit b422b75

Browse files
committed
feat: Adds functionality to provide privacy for sender. python-discord#1477
Adds functionality that instantly deletes messages if "anon" type was specified. Notifications and who is typing will still be sent, but it still provides some anonymity. Also fixes bug that sends the confirmation message to the receiver of the message (should be sender).
1 parent f8b6401 commit b422b75

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

bot/exts/holidays/valentines/be_my_valentine.py

+34-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async def lovefest_role(self, ctx: commands.Context) -> None:
4444
# @commands.cooldown(1, 1800, commands.BucketType.user)
4545
@commands.group(name="bemyvalentine", invoke_without_command=True)
4646
async def send_valentine(
47-
self, ctx: commands.Context, user: discord.Member, privacy_type: str | None = None, valentine_type: str | None = None
47+
self, ctx: commands.Context, user: discord.Member, privacy_type: str | None = None, anon: str | None = None, valentine_type: str | None = None
4848
) -> None:
4949
"""
5050
Send a valentine to a specified user with the lovefest role.
@@ -56,6 +56,24 @@ async def send_valentine(
5656
example: .bemyvalentine public Iceman Hey I love you, wanna hang around ? (sends the custom message publicly to Iceman)
5757
NOTE : AVOID TAGGING THE USER MOST OF THE TIMES.JUST TRIM THE '@' when using this command.
5858
"""
59+
60+
61+
if anon.lower() == "anon":
62+
# Delete the message containing the command right after it was sent to enforce anonymity.
63+
try:
64+
await ctx.message.delete()
65+
except discord.Forbidden:
66+
await ctx.send("I can't delete your message! Please check my permissions.")
67+
68+
69+
if anon not in ["anon", "signed"]:
70+
# Anonymity type wrongfully specified.
71+
raise commands.UserInputError(
72+
f"Specify if you want the message to be anonymous or not!"
73+
)
74+
75+
76+
5977
if ctx.guild is None:
6078
# This command should only be used in the server
6179
raise commands.UserInputError("You are supposed to use this command in the server.")
@@ -81,17 +99,25 @@ async def send_valentine(
8199
channel = self.bot.get_channel(Channels.sir_lancebot_playground)
82100
valentine, title = self.valentine_check(valentine_type)
83101

84-
embed = discord.Embed(
85-
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
86-
description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**",
87-
color=Colours.pink
88-
)
89-
102+
if anon.lower() == "anon":
103+
embed = discord.Embed(
104+
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
105+
description=f"{valentine} \n **{emoji_2}From an anonymous admirer{emoji_1}**",
106+
color=Colours.pink
107+
)
108+
109+
else:
110+
embed = discord.Embed(
111+
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
112+
description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**",
113+
color=Colours.pink
114+
)
115+
90116
if privacy_type.lower() == "private":
91117
# Send the message privately if "private" was speicified
92118
try:
93119
await user.send(embed=embed)
94-
await user.send(f"Your valentine has been **privately** delivered to {user.display_name}!")
120+
await ctx.author.send(f"Your valentine has been **privately** delivered to {user.display_name}!")
95121
except discord.Forbidden:
96122
await ctx.send(f"I couldn't send a private message to {user.display_name}. They may have DMs disabled.")
97123
else:

0 commit comments

Comments
 (0)