aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Rohan <[email protected]>2019-02-13 11:18:04 +0530
committerGravatar Rohan <[email protected]>2019-02-13 11:18:04 +0530
commit16642ebe29690eba15c592f6c153fbc4abfa4348 (patch)
tree0ce41c1c299b1107fca7f0458bf4115c782a39a3
parentim done working with the bemyvalentine command (diff)
Well i have done quite a few changes :
1) I have now made a USER_LOVEFEST list which will have all the members having the lovefest role.Whenever people use the command '.lovefest' to get themselfs the lovefest role,their name will be appended to the list. 2) incase the bot goes offline for some reason,then we need to again add members to USER_LOVEFEST list.So for this i added one more command called '.refreshlovefest' which adds all the members having lovefest role to the list 3) Basically the purpus of the USER_LOVEFEST list is when someone uses the bemyvalentine commands,and they dont provide a user,then a random user is selected from the USER_LOVEFEST list. these are the changes done .
-rw-r--r--bot/seasons/valentines/be_my_valentine.py52
1 files changed, 40 insertions, 12 deletions
diff --git a/bot/seasons/valentines/be_my_valentine.py b/bot/seasons/valentines/be_my_valentine.py
index 35ced8d0..e032a593 100644
--- a/bot/seasons/valentines/be_my_valentine.py
+++ b/bot/seasons/valentines/be_my_valentine.py
@@ -16,6 +16,7 @@ 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 = []
class BeMyValentine:
@@ -35,11 +36,30 @@ class BeMyValentine:
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]:
+ 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 !")
+ @commands.command(name='refreshlovefest')
+ async def refresh_user_lovefestlist(self, ctx):
+ """
+ Use this command to refresh the USER_VALENTINE list when the bot goes offline and then comes back online
+ """
+ USER_LOVEFEST.clear()
+ for member in ctx.guild.members:
+ for role in member.roles:
+ if role.id == Lovefest.role_id:
+ USER_LOVEFEST.append(member)
+ embed = discord.Embed(
+ title="USER_LOVEFEST list updated!",
+ description=f'''The USER_LOVEFEST has been refreshed,`bemyvalentine` and `bemyvalentine dm` commands can now
+ be used and there are {USER_LOVEFEST.__len__()} members having the lovefest role.''',
+ color=Colours.pink
+ )
+ await ctx.send(embed=embed)
+
@commands.cooldown(1, 1800, BucketType.user)
@commands.group(
name='bemyvalentine',
@@ -59,18 +79,22 @@ class BeMyValentine:
example: .bemyvalentine @Iceman#6508 Hey I love you, wanna hang around ? (sends the custom message to Iceman)
"""
+ 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."
+ return await ctx.send(msg)
+
channel = self.bot.get_channel(Lovefest.channel_id)
- random_user = []
if user == ctx.author:
+ # 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:
- for member in ctx.guild.members:
- for role in member.roles:
- if role.id == Lovefest.role_id:
- random_user.append(member)
- user = random.choice(random_user)
+ # 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
@@ -124,17 +148,20 @@ 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)
"""
- random_user = []
+ 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."
+ return await ctx.send(msg)
if user == ctx.author:
+ # 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:
- for member in ctx.guild.members:
- for role in member.roles:
- if role.id == Lovefest.role_id:
- random_user.append(member)
- user = random.choice(random_user)
+ # 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)
if valentine_type is None:
valentine, title = self.random_valentine()
@@ -165,6 +192,7 @@ class BeMyValentine:
)
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)
@staticmethod