You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fox-V3/lovecalculator/lovecalculator.py

53 lines
1.7 KiB

import aiohttp
import discord
from bs4 import BeautifulSoup
from redbot.core import commands
from typing import Any
Cog: Any = getattr(commands, "Cog", object)
class LoveCalculator(Cog):
"""Calculate the love percentage for two users!"""
def __init__(self, bot):
self.bot = bot
6 years ago
@commands.command(aliases=["lovecalc"])
async def lovecalculator(
self, ctx: commands.Context, lover: discord.Member, loved: discord.Member
):
"""Calculate the love percentage!"""
x = lover.display_name
y = loved.display_name
6 years ago
url = "https://www.lovecalculator.com/love.php?name1={}&name2={}".format(
x.replace(" ", "+"), y.replace(" ", "+")
)
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
soup_object = BeautifulSoup(await response.text(), "html.parser")
try:
6 years ago
description = (
soup_object.find("div", attrs={"class": "result score"}).get_text().strip()
)
except:
6 years ago
description = "Dr. Love is busy right now"
try:
z = description[:2]
z = int(z)
if z > 50:
6 years ago
emoji = ""
else:
6 years ago
emoji = "💔"
title = "Dr. Love says that the love percentage for {} and {} is:".format(x, y)
except:
6 years ago
emoji = ""
title = "Dr. Love has left a note for you."
6 years ago
description = emoji + " " + description + " " + emoji
em = discord.Embed(title=title, description=description, color=discord.Color.red())
await ctx.send(embed=em)