Skip to content

Commit 1e14def

Browse files
committed
feat: Adds the ability to send public/private messages in different channels. python-discord#1477
Adds the ability to send valentines messages publicly or privately to a person. If private, the message is sent in DMs (if possible) and if public it is sent in the current channel that the command was invoked in.
1 parent 45bf97f commit 1e14def

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

bot/exts/holidays/valentines/be_my_valentine.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ async def lovefest_role(self, ctx: commands.Context) -> None:
4141
"""
4242
raise MovedCommandError(MOVED_COMMAND)
4343

44-
@commands.cooldown(1, 1800, commands.BucketType.user)
44+
# @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, *, valentine_type: str | None = None
47+
self, ctx: commands.Context, user: discord.Member, privacy_type: str | None = None, valentine_type: str | None = None
4848
) -> None:
4949
"""
5050
Send a valentine to a specified user with the lovefest role.
5151
52-
syntax: .bemyvalentine [user] [p/poem/c/compliment/or you can type your own valentine message]
52+
syntax: .bemyvalentine [user] [public/private] [p/poem/c/compliment/or you can type your own valentine message]
5353
(optional)
5454
55-
example: .bemyvalentine Iceman#6508 p (sends a poem to Iceman)
56-
example: .bemyvalentine Iceman Hey I love you, wanna hang around ? (sends the custom message to Iceman)
55+
example: .bemyvalentine private Iceman#6508 p (sends a private poem to Iceman)
56+
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
"""
5959
if ctx.guild is None:
@@ -64,10 +64,18 @@ async def send_valentine(
6464
raise commands.UserInputError(
6565
f"You cannot send a valentine to {user} as they do not have the lovefest role!"
6666
)
67+
68+
if privacy_type not in ["public", "private"]:
69+
# Privacy type wrongfully specified.
70+
raise commands.UserInputError(
71+
f"Specify if you want the message to be sent privately or publicly!"
72+
)
73+
74+
# COMMENTED FOR TESTING PURPOSES
6775

68-
if user == ctx.author:
69-
# Well a user can't valentine himself/herself.
70-
raise commands.UserInputError("Come on, you can't send a valentine to yourself :expressionless:")
76+
# if user == ctx.author:
77+
# # Well a user can't valentine himself/herself.
78+
# raise commands.UserInputError("Come on, you can't send a valentine to yourself :expressionless:")
7179

7280
emoji_1, emoji_2 = self.random_emoji()
7381
channel = self.bot.get_channel(Channels.sir_lancebot_playground)
@@ -78,7 +86,20 @@ async def send_valentine(
7886
description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**",
7987
color=Colours.pink
8088
)
81-
await channel.send(user.mention, embed=embed)
89+
90+
if privacy_type.lower() == "private":
91+
# Send the message privately if "private" was speicified
92+
try:
93+
await user.send(embed=embed)
94+
await user.send(f"Your valentine has been **privately** delivered to {user.display_name}!")
95+
except discord.Forbidden:
96+
await ctx.send(f"I couldn't send a private message to {user.display_name}. They may have DMs disabled.")
97+
else:
98+
# Send the message publicly if "public" was speicified
99+
try:
100+
await ctx.send(user.mention, embed=embed)
101+
except discord.Forbidden:
102+
await ctx.send(f"I couldn't send a private message to {user.display_name}. They may have DMs disabled.")
82103

83104
@commands.cooldown(1, 1800, commands.BucketType.user)
84105
@send_valentine.command(name="secret")

0 commit comments

Comments
 (0)