diff options
author | 2019-02-14 10:36:43 +0000 | |
---|---|---|
committer | 2019-02-14 10:36:43 +0000 | |
commit | cb703c5915b203dcf71ecf4a222e36c610a7daea (patch) | |
tree | 9553650dcf1b81807d2e977ac109bd677d8ead4f | |
parent | Merge pull request #106 from python-discord/readme-update (diff) | |
parent | Update LoveCalculator to address requested changes (diff) |
Merge pull request #100 from darthdelay/lovecalculator
Add LoveCalculator as described in #96
-rw-r--r-- | bot/resources/valentines/love_matches.json | 58 | ||||
-rw-r--r-- | bot/seasons/valentines/lovecalculator.py | 71 |
2 files changed, 129 insertions, 0 deletions
diff --git a/bot/resources/valentines/love_matches.json b/bot/resources/valentines/love_matches.json new file mode 100644 index 00000000..a3d2c282 --- /dev/null +++ b/bot/resources/valentines/love_matches.json @@ -0,0 +1,58 @@ +{ + "0": { + "titles": [ + "\ud83d\udc9b When will you two marry? \ud83d\udc9b", + "\ud83d\udc9b Now kiss already \ud83d\udc9b" + ], + "text": "You two will most likely have the perfect relationship. But don't think that this means you don't have to do anything for it to work. Talking to each other and spending time together is key, even in a seemingly perfect relationship." + }, + "95": { + "titles": [ + "\ud83d\udc96 Love is in the air \ud83d\udc96", + "\ud83d\udc96 Planned your future yet? \ud83d\udc96" + ], + "text": "Your relationship will most likely work out perfect. This doesn't mean thought that you don't need to put effort into it. Talk to each other, spend time together, and you two won't have a hard time." + }, + "80": { + "titles": [ + "\ud83d\udc95 Aww look you two fit so well together \ud83d\udc95" + ], + "text": "Your relationship will most likely work out well. Don't hesitate on making contact with each other though, as your relationship might suffer from a lack of time spent together. Talking with each other and spending time together is key." + }, + "60": { + "titles": [ + "\u2764 So when will you two go on a date? \u2764" + ], + "text": "Your relationship will most likely work out. It won't be perfect and you two need to spend a lot of time together, but if you keep on having contact, the good times in your relationship will outweigh the bad ones." + }, + "45": { + "titles": [ + "\ud83d\udc98 You two are really close aren't you? \ud83d\udc98" + ], + "text": "Your relationship has a reasonable amount of working out. But do not overestimate yourself there. Your relationship will suffer good and bad times. Make sure to not let the bad times destroy your relationship, so do not hesitate to talk to each other, figure problems out together etc." + }, + "30": { + "titles": [ + "\ud83d\udc97 You seem like you are good friends \ud83d\udc97" + ], + "text": "The chance of this relationship working is not very high, but its not that low either. If you both want this relationship to work, and put time and effort into it, meaning spending time together, talking to each other etc., than nothing shall stand in your way." + }, + "20": { + "titles": [ + "\ud83d\udc9c You two seem like casual friends \ud83d\udc9c" + ], + "text": "The chance of this relationship working is not very high. You both need to put time and effort into this relationship, if you want it to work out well for both of you. Talk with each other about everything and don't lock yourself up. Spend time together. This will improve the chances of this relationship's survival by a lot." + }, + "5": { + "titles": [ + "\ud83d\udc99 A small acquaintance \ud83d\udc99" + ], + "text": "There might be a chance of this relationship working out somewhat well, but it is not very high. With a lot of time and effort you'll get it to work eventually, however don't count on it. It might fall apart quicker than you'd expect." + }, + "1": { + "titles": [ + "\ud83d\udc94 There's no real connection between you two \ud83d\udc94" + ], + "text": "The chance of this relationship working out is really low. You can get it to work, but with high costs and no guarantee of working out. Do not sit back, spend as much time together as possible, talk a lot with each other to increase the chances of this relationship's survival." + } +}
\ No newline at end of file diff --git a/bot/seasons/valentines/lovecalculator.py b/bot/seasons/valentines/lovecalculator.py new file mode 100644 index 00000000..9342f0fa --- /dev/null +++ b/bot/seasons/valentines/lovecalculator.py @@ -0,0 +1,71 @@ +import json +import logging +from pathlib import Path +from random import choice + +import discord +from discord.ext import commands + +from bot.constants import Roles + +log = logging.getLogger(__name__) + +with open(Path("bot", "resources", "valentines", "love_matches.json"), "r") as file: + LOVE_DATA = json.load(file) +LOVE_LEVELS = [int(x) for x in LOVE_DATA] + + +class LoveCalculator: + """ + A cog for calculating the love between two people + """ + def __init__(self, bot): + self.bot = bot + + @commands.command(aliases=('love_calculator', 'love_calc')) + @commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user) + async def love(self, ctx, name_one: discord.Member, name_two: discord.Member = None): + """ + Calculates the love between two given names + + DO NOT SPAM @mentions! There are five ways to hand over a name to this command: + 1. ID of the user + 2. Name + Discriminator of the user (name#discrim) (1) + 3. Username (1) + 4. Nickname (1) + 5. @mention + + Using method 1-4 is highly encouraged, as nobody likes unwanted pings + they'll count as spam. + Skipping the second name will lead to something awesome. + + *(1): If the name has any form of spacing, the name must be wrapped inside quotes. Example: + .love Ves Zappa Niko Laus -> Will not work + .love "Ves Zappa" "Niko Laus" -> Will work + """ + + if name_two is None: + staff = ctx.guild.get_role(Roles.helpers).members + name_two = choice(staff) + + love_meter = (name_one.id + name_two.id) % 100 + love_idx = str(sorted(x for x in LOVE_LEVELS if x <= love_meter)[-1]) + love_status = choice(LOVE_DATA[love_idx]["titles"]) + + embed = discord.Embed( + title=love_status, + description=( + f'{name_one.display_name} \u2764 {name_two.display_name}' + f' scored {love_meter}%!\n\u200b' + ), + color=discord.Color.dark_magenta() + ) + embed.add_field( + name='A letter from Dr. Love:', + value=LOVE_DATA[love_idx]["text"] + ) + + await ctx.message.channel.send(embed=embed) + + +def setup(bot): + bot.add_cog(LoveCalculator(bot)) |