if recipient is None

This commit is contained in:
2025-02-15 13:57:47 -05:00
parent 9d23438b13
commit 6463ace40c
9 changed files with 617 additions and 716 deletions

View File

@ -4,7 +4,7 @@
import traceback
import logging
import os
from typing import Any, Optional
from typing import Any, Optional, Union
import discord
import aiosqlite as sqlite3
from discord.ext import bridge, commands
@ -43,11 +43,15 @@ class LoveHate(commands.Cog):
"""
try:
if not user:
loves: list[tuple] = await self.db.get_lovehates(user=ctx.author.display_name, loves=True)
display_name = ctx.author.display_name
loves: Union[list[tuple], bool] = await self.db.get_lovehates(user=display_name,
loves=True)
if not loves:
return await ctx.respond("You don't seem to love anything...")
out_loves: list = []
if not isinstance(loves, list):
return
for love in loves:
(love,) = love
out_loves.append(love)
@ -55,11 +59,11 @@ class LoveHate(commands.Cog):
out_loves_str: str = self.join_with_and(out_loves)
return await ctx.respond(f"{ctx.author.mention} loves {out_loves_str}")
loves: list[tuple] = await self.db.get_lovehates(user=user.strip(), loves=True)
loves = await self.db.get_lovehates(user=user.strip(), loves=True)
if not loves:
return await ctx.respond(f"{user} doesn't seem to love anything...")
out_loves_str: str = self.join_with_and(out_loves)
out_loves_str = self.join_with_and(out_loves)
return await ctx.respond(f"{user} loves {out_loves_str}")
except Exception as e:
traceback.print_exc()
@ -77,15 +81,27 @@ class LoveHate(commands.Cog):
"""
try:
if not thing:
thing: str = ctx.author.display_name
if discord.utils.raw_mentions(thing):
_thing: str = ctx.author.display_name
else:
_thing = thing
if discord.utils.raw_mentions(_thing):
# There are mentions
thing_id: int = discord.utils.raw_mentions(thing)[0] # First mention
thing: str = self.bot.get_guild(ctx.guild.id).get_member(thing_id).display_name
thing_id: int = discord.utils.raw_mentions(_thing)[0] # First mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
thing_member: Optional[discord.Member] = guild.get_member(thing_id)
if not thing_member:
return
_thing = thing_member.display_name
who_loves: list[tuple] = await self.db.get_wholovehates(thing=thing,
if not _thing:
return
who_loves: Union[list, bool] = await self.db.get_wholovehates(thing=_thing,
loves=True)
if not who_loves:
if not isinstance(who_loves, list):
return await ctx.respond(f"I couldn't find anyone who loves {thing}...")
out_wholoves: list = []
@ -114,18 +130,28 @@ class LoveHate(commands.Cog):
"""
try:
if not thing:
thing: str = ctx.author.display_name
if discord.utils.raw_mentions(thing):
_thing: str = ctx.author.display_name
else:
_thing = thing
if discord.utils.raw_mentions(_thing):
# There are mentions
thing_id: int = discord.utils.raw_mentions(thing)[0] # First mention
thing: str = self.bot.get_guild(ctx.guild.id).get_member(thing_id).display_name
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
thing_id: int = discord.utils.raw_mentions(_thing)[0] # First mention
thing_member: Optional[discord.Member] = guild.get_member(thing_id)
if not thing_member:
return
_thing = thing_member.display_name
who_hates: list[tuple] = await self.db.get_wholovehates(thing=thing,
who_hates: Union[list[tuple], bool] = await self.db.get_wholovehates(thing=_thing,
hates=True)
if not who_hates:
return await ctx.respond(f"I couldn't find anyone who hates {thing}...")
out_whohates: list = []
if not isinstance(who_hates, list):
return
for hater in who_hates:
(hater,) = hater
out_whohates.append(str(hater))
@ -170,26 +196,24 @@ class LoveHate(commands.Cog):
"""
try:
if not user:
hates: list[tuple] = await self.db.get_lovehates(user=ctx.author.display_name,
display_name = ctx.author.display_name
hates: Union[list[tuple], bool] = await self.db.get_lovehates(user=display_name,
hates=True)
if not hates:
return await ctx.respond("You don't seem to hate anything...")
out_hates: list = []
for hated_thing in hates:
(hated_thing,) = hated_thing
out_hates.append(str(hated_thing))
out_hates_str: str = self.join_with_and(out_hates)
return await ctx.respond(f"{ctx.author.mention} hates {out_hates_str}")
hates: list[tuple] = await self.db.get_lovehates(user=user.strip(), hates=True)
if not hates:
return await ctx.respond(f"{user} doesn't seem to hate anything...")
else:
hates = await self.db.get_lovehates(user=user.strip(), hates=True)
if not hates:
return await ctx.respond(f"{user} doesn't seem to hate anything...")
out_hates_str: str = self.join_with_and(hates)
out_hates: list = []
if not isinstance(hates, list):
return
for hated_thing in hates:
(hated_thing,) = hated_thing
out_hates.append(str(hated_thing))
out_hates_str: str = self.join_with_and(out_hates)
return await ctx.respond(f"{user} hates {out_hates_str}")
except Exception as e:
await ctx.respond(f"Error: {str(e)}")
@ -209,7 +233,13 @@ class LoveHate(commands.Cog):
if discord.utils.raw_mentions(thing):
# There are mentions
thing_id: int = discord.utils.raw_mentions(thing)[0] # First mention
thing: str = self.bot.get_guild(ctx.guild.id).get_member(thing_id).display_name
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild)
if not guild:
return
thing_member: Optional[discord.Member] = guild.get_member(thing_id)
if not thing_member:
return
thing = thing_member.display_name
love: str = await self.db.update(ctx.author.display_name,
thing, 1)
@ -232,7 +262,13 @@ class LoveHate(commands.Cog):
if discord.utils.raw_mentions(thing):
# There are mentions
thing_id: int = discord.utils.raw_mentions(thing)[0] # First mention
thing: str = self.bot.get_guild(ctx.guild.id).get_member(thing_id).display_name
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
thing_member: Optional[discord.Member] = guild.get_member(thing_id)
if not thing_member:
return
thing = thing_member.display_name
hate: str = await self.db.update(ctx.author.display_name,
thing, -1)
return await ctx.respond(hate)