diff options
author | 2019-02-15 10:31:56 +0530 | |
---|---|---|
committer | 2019-02-15 10:31:56 +0530 | |
commit | d55fde242cc8869b735bf0726f70fe9bde255a20 (patch) | |
tree | 30d5f843ba868a97463fdd80ac7e911058f686de /bot | |
parent | I have made the command .refreshlovefest modertaor only using the decorator @... (diff) |
The did the follwing changes :
> 1)The made a static method to generate random heart emoji
> 2)I made a static method to get a random user using lovefest role if the person using the command dosent provide one
> 3)i made a valentines attribute in the init method taking in the json data
> 4) made the poem and compliment /p/c as case insensitive by using lower() to the user input
Diffstat (limited to 'bot')
-rw-r--r-- | bot/resources/valentines/bemyvalentine_valentines.json | 4 | ||||
-rw-r--r-- | bot/seasons/valentines/be_my_valentine.py | 190 |
2 files changed, 99 insertions, 95 deletions
diff --git a/bot/resources/valentines/bemyvalentine_valentines.json b/bot/resources/valentines/bemyvalentine_valentines.json index 17db8ad1..66c98adb 100644 --- a/bot/resources/valentines/bemyvalentine_valentines.json +++ b/bot/resources/valentines/bemyvalentine_valentines.json @@ -10,7 +10,7 @@ "message" :"If you were my island, then I'd be your sea,\ncaressing your shores, soft and gentle I'd be.\nMy tidal embrace would leave gifts on your sands,\nbut by current and storm, I'd ward your gentle lands." }, { - "message" :"If you were love's promise, then I would be time,\nyour constant companion till stars align. And though we are mere mortals,\ntrue love is divine,and my devotion eternal,\nto my one valentine." + "message" :"If you were love's promise, then I would be time,\nyour constant companion till stars align.\nAnd though we are mere mortals,\ntrue love is divine,and my devotion eternal,\nto my one valentine." }, { "message" :"Have I told you,\nValentine, That I’m all wrapped up in you?\nMy feelings for you bring to me A joy I never knew.\n \n You light up everything for me; In my heart you shine;\nIlluminating my whole life,\nMy darling Valentine." @@ -34,7 +34,7 @@ "message" :"My love for you is like the raging sea,\nSo powerful and deep it will forever be.\nThrough storm, wind, and heavy rain, It will withstand every pain.\nOur hearts are so pure and love so sweet.\nI love you more with every heartbeat!" }, { - "message" :"A million stars up in the sky.\nOne shines brighter - I can't deny.\nA love so precious, a love so true, a love that comes from me to you.\nThe angels sing when you are near.\nWithin your arms I have nothing to fear.\nYou always know just what to say.\nJust talking to you makes my day.\nI love you, honey, with all of my heart.\nTogether forever and never to part." + "message" :"A million stars up in the sky.\nOne shines brighter - I can't deny.\nA love so precious, a love so true,\na love that comes from me to you.\nThe angels sing when you are near.\nWithin your arms I have nothing to fear.\nYou always know just what to say.\nJust talking to you makes my day.\nI love you, honey, with all of my heart.\nTogether forever and never to part." }, { "message" :"What do I do,\nWhen I'm still in love with you?\nYou walked away, Cause you didn't want to stay.\nYou broke my heart, you tore me apart.\nEvery day I wait for you, Telling myself our love was true.\nBut when you don't show, more tears start to flow.\nThat's when I know I have to let go." 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") |