Skip to content

Bemyvalentine patch #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions bot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class EnvConfig(


class _Channels(EnvConfig, env_prefix="channels_"):
general: int = 123123123123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything changes made just for testing should be reverted (though I'm not really sure why this would be needed, when you can just use a channel that is already configured as whitelisted)

algos_and_data_structs: int = 650401909852864553
bot_commands: int = 267659945086812160
community_meta: int = 267659945086812160
Expand Down Expand Up @@ -312,6 +313,7 @@ class _Reddit(EnvConfig, env_prefix="reddit_"):

# Whitelisted channels
WHITELISTED_CHANNELS = (
Channels.general,
Channels.bot_commands,
Channels.sir_lancebot_playground,
Channels.off_topic_0,
Expand Down
68 changes: 57 additions & 11 deletions bot/exts/holidays/valentines/be_my_valentine.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,39 @@ async def lovefest_role(self, ctx: commands.Context) -> None:
"""
raise MovedCommandError(MOVED_COMMAND)

@commands.cooldown(1, 1800, commands.BucketType.user)
# @commands.cooldown(1, 1800, commands.BucketType.user)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this was done while testing, but should be reverted now. To keep git history clean, avoid committing temporary changes.

@commands.group(name="bemyvalentine", invoke_without_command=True)
async def send_valentine(
self, ctx: commands.Context, user: discord.Member, *, valentine_type: str | None = None
self, ctx: commands.Context, user: discord.Member, privacy_type: str | None = None, anon: str | None = None, valentine_type: str | None = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typying.Literal can be used to make discord.py check if the argument is valid https://discordpy.readthedocs.io/en/latest/ext/commands/commands.html#typing-literal

This would simplify the logic later on.

) -> None:
"""
Send a valentine to a specified user with the lovefest role.

syntax: .bemyvalentine [user] [p/poem/c/compliment/or you can type your own valentine message]
syntax: .bemyvalentine [user] [public/private] [anon/signed] [p/poem/c/compliment/or you can type your own valentine message]
(optional)

example: .bemyvalentine Iceman#6508 p (sends a poem to Iceman)
example: .bemyvalentine Iceman Hey I love you, wanna hang around ? (sends the custom message to Iceman)
example: .bemyvalentine Iceman#6508 private anon p (sends an anonymous private poem through DM to Iceman)
example: .bemyvalentine Iceman public signed Hey I love you, wanna hang around ? (sends the custom message publicly and signed to Iceman in the current channel)
NOTE : AVOID TAGGING THE USER MOST OF THE TIMES.JUST TRIM THE '@' when using this command.
"""


if anon.lower() == "anon":
# Delete the message containing the command right after it was sent to enforce anonymity.
try:
await ctx.message.delete()
except discord.Forbidden:
await ctx.send("I can't delete your message! Please check my permissions.")


if anon not in ["anon", "signed"]:
# Anonymity type wrongfully specified.
raise commands.UserInputError(
f"Specify if you want the message to be anonymous or not!"
)



if ctx.guild is None:
# This command should only be used in the server
raise commands.UserInputError("You are supposed to use this command in the server.")
Expand All @@ -64,6 +82,13 @@ async def send_valentine(
raise commands.UserInputError(
f"You cannot send a valentine to {user} as they do not have the lovefest role!"
)

if privacy_type not in ["public", "private"]:
# Privacy type wrongfully specified.
raise commands.UserInputError(
f"Specify if you want the message to be sent privately or publicly!"
)


if user == ctx.author:
# Well a user can't valentine himself/herself.
Expand All @@ -73,12 +98,33 @@ async def send_valentine(
channel = self.bot.get_channel(Channels.sir_lancebot_playground)
valentine, title = self.valentine_check(valentine_type)

embed = discord.Embed(
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**",
color=Colours.pink
)
await channel.send(user.mention, embed=embed)
if anon.lower() == "anon":
embed = discord.Embed(
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
description=f"{valentine} \n **{emoji_2}From an anonymous admirer{emoji_1}**",
color=Colours.pink
)

else:
embed = discord.Embed(
title=f"{emoji_1} {title} {user.display_name} {emoji_2}",
description=f"{valentine} \n **{emoji_2}From {ctx.author}{emoji_1}**",
color=Colours.pink
)
Comment on lines +101 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is unnecessary duplication here, you could just have something like

from_user = "an anonymous admirer" if anon.lower() == "anon" else ctx.author

and format that into a single embed call.


if privacy_type.lower() == "private":
# Send the message privately if "private" was speicified
try:
await user.send(embed=embed)
await ctx.author.send(f"Your valentine has been **privately** delivered to {user.display_name}!")
except discord.Forbidden:
await ctx.send(f"I couldn't send a private message to {user.display_name}. They may have DMs disabled.")
else:
# Send the message publicly if "public" was speicified
try:
await ctx.send(user.mention, embed=embed)
except discord.Forbidden:
await ctx.send(f"I couldn't send a private message to {user.display_name}. They may have DMs disabled.")

@commands.cooldown(1, 1800, commands.BucketType.user)
@send_valentine.command(name="secret")
Expand Down
Empty file added tests/__init__.py
Empty file.
Empty file added tests/exts/__init__.py
Empty file.
Empty file added tests/exts/holidays/__init__.py
Empty file.
Empty file.
Loading
Loading