aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons')
-rw-r--r--bot/seasons/valentines/be_my_valentine.py190
1 files changed, 97 insertions, 93 deletions
diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py
index 1c387f66..060cef3b 100644
--- a/bot/seasons/valentines/be_my_valentine.py
+++ b/bot/seasons/valentines/be_my_valentine.py
@@ -14,36 +14,47 @@ from bot.decorators import with_role
log = logging.getLogger(__name__)
HEART_EMOJIS = [":heart:", ":gift_heart:", ":revolving_hearts:", ":sparkling_heart:", ":two_hearts:"]
-EMOJI_1 = random.choice(HEART_EMOJIS)
-EMOJI_2 = random.choice(HEART_EMOJIS)
USER_LOVEFEST = []
-JSON_FILE = open(Path('bot', 'resources', 'VALENTINES', 'bemyvalentine_valentines.json'), 'r', encoding="utf8")
-VALENTINES = load(JSON_FILE)
class BeMyValentine:
"""
- A cog that sends VALENTINES to other users !
+ A cog that sends valentines to other users !
"""
id = Lovefest.role_id
- def __init__(self, bot):
+ def __init__(self, bot, valentines):
self.bot = bot
+ self.valentines = valentines
- @commands.command(name="lovefest")
+ @commands.group(name="lovefest", invoke_without_command=True)
async def add_role(self, ctx):
"""
This command adds people to the lovefest role.
"""
user = ctx.author
role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id)
- if id not in [role.id for role in ctx.message.author.roles]:
+ if Lovefest.role_id not in [role.id for role in ctx.message.author.roles]:
USER_LOVEFEST.append(ctx.author)
await user.add_roles(role)
await ctx.send("The Lovefest role has been added !")
else:
await ctx.send("You already have the role !")
+ @add_role.command(name="remove")
+ async def remove_role(self, ctx):
+ """
+ This command removes the lovefest role.
+ """
+ user = ctx.author
+ role = discord.utils.get(ctx.guild.roles, id=Lovefest.role_id)
+ if Lovefest.role_id not in [role.id for role in ctx.message.author.roles]:
+ await ctx.send("You dont have the lovefest role.")
+ else:
+ USER_LOVEFEST.remove(ctx.author)
+ await user.remove_roles(role)
+ await ctx.send("The lovefest role has been successfully removed !")
+
@with_role(Roles.moderator)
@commands.command(name='refreshlovefest')
async def refresh_user_lovefestlist(self, ctx):
@@ -76,6 +87,8 @@ class BeMyValentine:
example: .bemyvalentine @Iceman#6508 p (sends a poem to Iceman)
example: .bemyvalentine @Iceman#6508 Hey I love you, wanna hang around ? (sends the custom message to Iceman)
"""
+ emoji_1, emoji_2 = self.random_emoji()
+
if ctx.guild is None:
# This command should only be used in the server
msg = "You are supposed to use this command in the server."
@@ -88,42 +101,32 @@ class BeMyValentine:
await ctx.send('Come on dude, you cant send a valentine to yourself :expressionless:')
elif user is None:
+ user = self.random_user(ctx.author)
# just making sure that the random does not pick up the same user(ctx.author)
- USER_LOVEFEST.remove(ctx.author)
- user = random.choice(USER_LOVEFEST)
- USER_LOVEFEST.append(ctx.author)
- if valentine_type is None:
- # grabs a random valentine -can be a poem or a good message
- valentine, title = self.random_valentine()
- embed = discord.Embed(
- title=f"{EMOJI_1} {title} {user.display_name}{EMOJI_2}",
- color=Colours.pink
- )
-
- elif valentine_type in ['p', 'poem']:
- valentine = self.valentine_poem()
- embed = discord.Embed(
- title=f"{EMOJI_1} A poem dedicated to {user.display_name}{EMOJI_2}",
- color=Colours.pink
- )
-
- elif valentine_type in ['c', 'compliment']:
- valentine = self.valentine_compliment()
- embed = discord.Embed(
- title=f"{EMOJI_1} A compliment for {user.display_name}{EMOJI_2}",
- color=Colours.pink
- )
- else:
- # in this case, the user decides to type his own valentine.
- valentine = valentine_type
- embed = discord.Embed(
- title=f'{EMOJI_1}A message for {user.display_name}{EMOJI_2}',
- color=Colours.pink
- )
-
- embed.description = f'{valentine} \n **{EMOJI_2}From {ctx.author}{EMOJI_1}**'
- await channel.send(user.mention, embed=embed)
+ if valentine_type is None:
+ # grabs a random valentine -can be a poem or a good message
+ valentine, title = self.random_valentine()
+
+ elif valentine_type.lower() in ['p', 'poem']:
+ valentine = self.valentine_poem()
+ title = f'A poem dedicated to'
+
+ elif valentine_type.lower() in ['c', 'compliment']:
+ valentine = self.valentine_compliment()
+ title = f'A compliment for'
+
+ else:
+ # in this case, the user decides to type his own valentine.
+ valentine = valentine_type
+ title = f'A message for'
+
+ 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)
@commands.cooldown(1, 1800, BucketType.user)
@send_valentine.command(name='dm')
@@ -142,6 +145,7 @@ class BeMyValentine:
example : .bemyvalentine dm Iceman#6508 Hey I love you, wanna hang around ? (sends the custom message to Iceman
in DM making you anonymous)
"""
+ emoji_1, emoji_2 = self.random_emoji()
if ctx.guild is not None:
# This command is only DM specific
msg = "You are not supposed to use this command in the server, DM the command to the bot."
@@ -151,78 +155,78 @@ class BeMyValentine:
# Well a user cant valentine himself/herself.
await ctx.send('Come on dude, you cant send a valentine to yourself :expressionless:')
- elif user is None:
+ if user is None:
# just making sure that the random dosent pick up the same user(ctx.author)
- USER_LOVEFEST.remove(ctx.author)
- user = random.choice(USER_LOVEFEST)
- USER_LOVEFEST.append(ctx.author)
+ user = self.random_user(ctx.author)
+
+ if valentine_type is None:
+ valentine, title = self.random_valentine()
- if valentine_type is None:
- valentine, title = self.random_valentine()
- embed = discord.Embed(
- title=f"{EMOJI_1} {title} {user.display_name}{EMOJI_2}",
- color=Colours.pink
- )
-
- elif valentine_type in ['p', 'poem']:
- valentine = self.valentine_poem()
- embed = discord.Embed(
- title=f"{EMOJI_1} A poem dedicated to {user.display_name}{EMOJI_2}",
- color=Colours.pink
- )
-
- elif valentine_type in ['c', 'compliment']:
- valentine = self.valentine_compliment()
- embed = discord.Embed(
- title=f"{EMOJI_1} A compliment for {user.display_name}{EMOJI_1}",
- color=Colours.pink
- )
- else:
- # in this case, the user decides to type his own valentine.
- valentine = valentine_type
- embed = discord.Embed(
- title=f'{EMOJI_1}A message for {user.display_name}{EMOJI_2}',
- color=Colours.pink
- )
-
- embed.description = f'{valentine} \n **{EMOJI_2}From anonymous{EMOJI_1}**'
- await ctx.author.send(f"Your message has been sent to {user}")
- await user.send(embed=embed)
+ elif valentine_type.lower() in ['p', 'poem']:
+ valentine = self.valentine_poem()
+ title = f'A poem dedicated to'
+
+ elif valentine_type.lower() in ['c', 'compliment']:
+ valentine = self.valentine_compliment()
+ title = f'A compliment for'
+
+ else:
+ # in this case, the user decides to type his own valentine.
+ valentine = valentine_type
+ title = f'A message for'
+
+ embed = discord.Embed(
+ title=f'{emoji_1}{title} {user.display_name}{emoji_2}',
+ description=f'{valentine} \n **{emoji_2}From anonymous{emoji_1}**',
+ color=Colours.pink
+ )
+ await ctx.author.send(f"Your message has been sent to {user}")
+ await user.send(embed=embed)
+
+ @staticmethod
+ def random_user(author):
+ USER_LOVEFEST.remove(author)
+ user = random.choice(USER_LOVEFEST)
+ USER_LOVEFEST.append(author)
+ return user
@staticmethod
- def random_valentine():
+ def random_emoji():
+ EMOJI_1 = random.choice(HEART_EMOJIS)
+ EMOJI_2 = random.choice(HEART_EMOJIS)
+ return EMOJI_1, EMOJI_2
+
+ def random_valentine(self):
"""
Grabs a random poem or a compliment (any message).
"""
- valentine_poem = random.choice(VALENTINES['valentine_poems'])
- valentine_compliment = random.choice(VALENTINES['valentine_compliments'])
- JSON_FILE.close()
+ valentine_poem = random.choice(self.valentines['valentine_poems'])
+ valentine_compliment = random.choice(self.valentines['valentine_compliments'])
random_valentine = random.choice([valentine_compliment, valentine_poem])
if random_valentine == valentine_poem:
- message_type = 'A poem dedicated to'
+ title = 'A poem dedicated to'
else:
- message_type = 'A compliment for '
- return random_valentine['message'], message_type
+ title = 'A compliment for '
+ return random_valentine['message'], title
- @staticmethod
- def valentine_poem():
+ def valentine_poem(self):
"""
Grabs a random poem.
"""
- valentine_poem = random.choice(VALENTINES['valentine_poems'])
- JSON_FILE.close()
+ valentine_poem = random.choice(self.valentines['valentine_poems'])
return valentine_poem['message']
- @staticmethod
- def valentine_compliment():
+ def valentine_compliment(self):
"""
Grabs a random compliment.
"""
- valentine_compliment = random.choice(VALENTINES['valentine_compliments'])
- JSON_FILE.close()
+ valentine_compliment = random.choice(self.valentines['valentine_compliments'])
return valentine_compliment['message']
def setup(bot):
- bot.add_cog(BeMyValentine(bot))
+ JSON_FILE = open(Path('bot', 'resources', 'valentines', 'bemyvalentine_valentines.json'), 'r', encoding="utf8")
+ valentines = load(JSON_FILE)
+ bot.add_cog(BeMyValentine(bot, valentines))
+ JSON_FILE.close()
log.debug("Be My Valentine cog loaded")