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

68 lines
2.2 KiB

import logging
import aiohttp
import discord
from bs4 import BeautifulSoup
from redbot.core import commands
from redbot.core.commands import Cog
log = logging.getLogger("red.fox_v3.chatter")
class LoveCalculator(Cog):
"""Calculate the love percentage for two users!"""
def __init__(self, bot):
super().__init__()
self.bot = bot
async def red_delete_data_for_user(self, **kwargs):
"""Nothing to delete"""
return
6 years ago
@commands.command(aliases=["lovecalc"])
async def lovecalculator(
4 years ago
self, ctx: commands.Context, lover: discord.Member, loved: discord.Member
6 years ago
):
"""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(headers={"Connection": "keep-alive"}) as session:
async with session.get(url) as response:
log.debug(f"{response=}")
assert response.status == 200
soup_object = BeautifulSoup(await response.text(), "html.parser")
try:
6 years ago
description = (
soup_object.find("div", class_="result__score").get_text().strip()
6 years ago
)
except:
6 years ago
description = "Dr. Love is busy right now"
result_image = soup_object.find("img", class_="result__image").get("src")
result_text = soup_object.find("div", class_="result-text").get_text()
result_text = " ".join(result_text.split())
try:
z = description[:2]
z = int(z)
if z > 50:
6 years ago
emoji = ""
else:
6 years ago
emoji = "💔"
title = f"Dr. Love says that the love percentage for {x} and {y} is: {emoji} {description} {emoji}"
except:
6 years ago
title = "Dr. Love has left a note for you."
em = discord.Embed(title=title, description=result_text, color=discord.Color.red())
if result_image:
em.set_image(url=f"https://www.lovecalculator.com/{result_image}")
await ctx.send(embed=em)