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

@ -8,11 +8,12 @@ import random
from typing import Optional, LiteralString
import logging
import discord
from .misc_util import Util
from cogs.misc_util import Util
import aiosqlite as sqlite3
from sh import cowsay as cow_say, fortune # pylint: disable=no-name-in-module
from discord.ext import bridge, commands, tasks
from disc_havoc import Havoc
from constructors import MiscException
# pylint: disable=bare-except, broad-exception-caught, broad-exception-raised, global-statement
# pylint: disable=too-many-lines, invalid-name
@ -64,7 +65,7 @@ class Misc(commands.Cog):
global BOT_CHANIDS
BOT_CHANIDS = self.bot.BOT_CHANIDS
def is_spamchan() -> bool: # pylint: disable=no-method-argument
def is_spamchan() -> bool: # type: ignore
"""Check if channel is spamchan"""
def predicate(ctx):
try:
@ -74,9 +75,9 @@ class Misc(commands.Cog):
except:
traceback.print_exc()
return False
return commands.check(predicate)
return commands.check(predicate) # type: ignore
def is_spamchan_or_drugs() -> bool: # pylint: disable=no-method-argument
def is_spamchan_or_drugs() -> bool: # type: ignore
"""Check if channel is spamchan or drugs chan"""
def predicate(ctx):
try:
@ -86,10 +87,10 @@ class Misc(commands.Cog):
except:
traceback.print_exc()
return False
return commands.check(predicate)
return commands.check(predicate) # type: ignore
async def get_random_guild_member(self, online_only: Optional[bool] = False) -> str:
async def get_random_guild_member(self, online_only: Optional[bool] = False) -> Optional[str]:
"""
Get Random Guild Member
Args:
@ -97,7 +98,9 @@ class Misc(commands.Cog):
Returns:
str
"""
guild = self.bot.get_guild(1145182936002482196)
guild: Optional[discord.Guild] = self.bot.get_guild(1145182936002482196)
if not guild:
return None
if not online_only:
guild_members = [str(member.display_name) for member in guild.members if not member.bot]
else:
@ -115,14 +118,16 @@ class Misc(commands.Cog):
None
"""
try:
stats_embed: discord.Embed = await self.util.get_stats_embed()
stats_embed: Optional[discord.Embed] = await self.util.get_stats_embed()
if not stats_embed:
return
return await ctx.respond(embed=stats_embed)
except Exception as e:
traceback.print_exc()
return await ctx.respond(f"Error: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def listcoffees(self, ctx) -> None:
"""
List Available Coffees
@ -142,8 +147,8 @@ class Misc(commands.Cog):
traceback.print_exc()
return await ctx.respond(f"Error: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def listshoves(self, ctx) -> None:
"""
List Available Fates for shove command
@ -187,7 +192,10 @@ class Misc(commands.Cog):
'9': '9',
}
with ctx.channel.typing():
(days, hours, minutes, seconds, ms, us) = self.util.get_days_to_xmas() # pylint: disable=unused-variable
countdown = self.util.get_days_to_xmas()
if not isinstance(countdown, tuple) or len(countdown) < 6:
return await ctx.respond("Oops, Christmas is cancelled.") # Invalid countdown from util
(days, hours, minutes, seconds, ms, _) = countdown
now: datetime.datetime = datetime.datetime.now()
if now.month == 12 and now.day == 25:
return await ctx.respond("# IT IS CHRISTMAS!!!!!!!!\n-# keep the change, you filthy animal")
@ -235,19 +243,24 @@ class Misc(commands.Cog):
None
"""
try:
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
else:
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
with ctx.channel.typing():
insult: str = await self.util.get_insult(recipient)
if insult:
@ -272,16 +285,21 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
else:
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
with ctx.channel.typing():
compliment: str = await self.util.get_compliment(recipient)
if compliment:
@ -304,17 +322,25 @@ class Misc(commands.Cog):
"""
try:
if not recipient:
recipient: str = ctx.author.display_name
recipient = ctx.author.display_name
else:
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_id = discord.utils.raw_mentions(recipient)[0] # First mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
(choice_name, choice_category, choice_description) = await self.util.get_whisky()
whisky: Optional[tuple] = await self.util.get_whisky()
if not whisky:
raise MiscException("Failed to get whisky from db")
(choice_name, choice_category, choice_description) = whisky
embed: discord.Embed = discord.Embed(title=f"Whisky for {recipient}: {choice_name}",
description=choice_description.strip())
embed.add_field(name="Category", value=choice_category, inline=True)
@ -339,17 +365,27 @@ class Misc(commands.Cog):
"""
try:
if not recipient:
recipient: str = ctx.author.display_name
recipient = ctx.author.display_name
else:
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_id = discord.utils.raw_mentions(recipient)[0] # First mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
(choice_name, choice_ingredients) = await self.util.get_drink()
recipient = discord.utils.escape_mentions(recipient.strip())
if not recipient:
return
drink: Optional[tuple] = await self.util.get_drink()
if not drink:
raise MiscException("Failed to get drink from db.")
(choice_name, choice_ingredients) = drink
await ctx.respond(f"*is mixing up **{choice_name}** for {recipient.strip()}*")
embed: discord.Embed = discord.Embed(title=f"Cocktail for {recipient}",
description=choice_name)
@ -377,20 +413,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*sprays **{recipient_normal}** with water*")
await self.util.increment_counter("water_sprays")
@ -412,20 +452,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
if not recipient:
recipient = authorDisplay.strip()
recipient_normal = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*passes **{recipient_normal}** a barf bag*")
await self.util.increment_counter("barf_bags")
@ -448,30 +492,34 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
if recipient == "rhodes":
tea: str = "a cup of Harney & Sons Hot Cinnamon Spice Tea"
tea = "a cup of Harney & Sons Hot Cinnamon Spice Tea"
elif ctx.author.id == 992437729927376996 or recipient.lower() in ["kriegerin",
"traurigkeit",
"krieg",
"kriegs",
"cyberkrieg",
"ck"]:
tea: str = "a cup of earl grey, light and sweet"
tea = "a cup of earl grey, light and sweet"
response = await ctx.respond(f"*hands **{recipient_normal}** {tea}*")
await self.util.increment_counter("teas")
try:
@ -483,8 +531,8 @@ class Misc(commands.Cog):
traceback.print_exc()
return await ctx.respond(f"Failed: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def cowsay(self, ctx, *,
message: str) -> None:
"""
@ -505,8 +553,8 @@ class Misc(commands.Cog):
return await ctx.respond(f"Failed: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def fortune(self, ctx,
cowfile: Optional[str] = None) -> None:
"""
@ -518,7 +566,7 @@ class Misc(commands.Cog):
"""
try:
if not cowfile:
cowfile: str = random.choice(self.COWS).replace(".cow", "")
cowfile = random.choice(self.COWS).replace(".cow", "")
if not f'{cowfile}.cow' in self.COWS:
return await ctx.respond(f"Unknown cow {cowfile}, who dat?")
@ -531,8 +579,8 @@ class Misc(commands.Cog):
traceback.print_exc()
return await ctx.respond(f"Failed: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def listcows(self, ctx) -> None:
"""
List available .cow files (for cowsay)
@ -544,7 +592,7 @@ class Misc(commands.Cog):
cow_list: str = ""
try:
for cow in self.COWS:
cow: str = cow.replace(".cow", "")
cow = cow.replace(".cow", "")
cow_list += f"- **{cow}**\n"
embed: discord.Embed = discord.Embed(title="List of .cows",
@ -568,20 +616,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*doses **{recipient_normal}** with Zyklon-B*")
await self.util.increment_counter("cyanides")
@ -591,7 +643,7 @@ class Misc(commands.Cog):
except Exception as e:
logging.debug("Failed to add cynaide reaction: %s",
str(e))
except:
except Exception as e:
traceback.print_exc()
return await ctx.respond(f"Failed: {str(e)}")
@ -609,20 +661,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*doses **{recipient_normal}** with school gravy*")
await self.util.increment_counter("gravies")
@ -650,20 +706,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*hands **{recipient_normal}** a cold glass of water*")
await self.util.increment_counter("waters")
@ -692,20 +752,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*shoves **{recipient_normal}** {chosen_fate}*")
await self.util.increment_counter("shoves")
@ -727,22 +791,28 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
chosen_coffee: str = self.util.get_coffee()
chosen_coffee: Optional[str] = self.util.get_coffee()
if not chosen_coffee:
return
response = await ctx.respond(f"*hands **{recipient_normal}** {chosen_coffee}*")
await self.util.increment_counter("coffees")
try:
@ -768,24 +838,31 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
else:
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
chosen_cookie: dict = await self.util.get_cookie()
chosen_cookie: Optional[dict] = await self.util.get_cookie()
if not chosen_cookie:
raise MiscException("Failed to get cookie from db.")
embed: discord.Embed = discord.Embed(title=f"Cookie for {recipient}",
description=f"Have a {chosen_cookie.get('name')}",
colour=discord.Colour.orange(),
image=chosen_cookie.get('image_url'))
embed.add_field(name="Origin",
value=chosen_cookie.get('origin'))
value=chosen_cookie.get('origin', 'N/A'))
await ctx.respond(embed=embed)
except Exception as e:
traceback.print_exc()
@ -803,20 +880,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*hands **{recipient_normal}** 2 warm hashbrowns*")
await self.util.increment_counter("hashbrowns")
@ -838,20 +919,24 @@ class Misc(commands.Cog):
authorDisplay = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*serves **{recipient_normal}** a plate of ritalini* 😉")
await response.add_reaction(emoji="💊")
@ -875,20 +960,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*hands **{recipient_normal}** a grilled cheese*")
await self.util.increment_counter("grilled_cheeses")
@ -910,20 +999,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
await ctx.respond(f"*hands **{recipient_normal}** a hot bowl of soup*")
await self.util.increment_counter("soups")
@ -945,18 +1038,22 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient = discord.utils.escape_mentions(recipient.strip())
try:
@ -981,20 +1078,24 @@ class Misc(commands.Cog):
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*hands **{recipient_normal}** a side of bacon*")
await response.add_reaction(emoji="🥓")
@ -1017,20 +1118,24 @@ class Misc(commands.Cog):
authorDisplay = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.author.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*sends **{recipient_normal}** to the Gallows to be hanged asynchronely*")
await self.util.increment_counter("hangings")
@ -1043,8 +1148,7 @@ class Misc(commands.Cog):
await ctx.respond(f"Failed: {str(e)}")
traceback.print_exc()
return
@bridge.bridge_command()
async def touch(self, ctx, *,
recipient: Optional[str] = None) -> None:
@ -1056,9 +1160,12 @@ class Misc(commands.Cog):
Returns:
None
"""
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
no_self_touch: str = ", don't fucking touch yourself here. You disgust me."
if recipient is None:
if not recipient:
recipient_normal: str = ctx.author.mention
await ctx.respond(f"{recipient_normal}{no_self_touch}")
try:
@ -1066,18 +1173,21 @@ class Misc(commands.Cog):
except Exception as e:
logging.debug("Failed to add puke reactin for touch command: %s",
str(e))
return await self.util.increment_counter("touch_denials")
await self.util.increment_counter("touch_denials")
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
response = await ctx.respond(f"*touches **{recipient_normal}** for **{ctx.author.mention}** because they wouldn't touch them with a shitty stick!*")
await self.util.increment_counter("touches")
@ -1090,8 +1200,8 @@ class Misc(commands.Cog):
traceback.print_exc()
return await ctx.respond(f"Failed: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def qajoke(self, ctx) -> None:
"""
Get a joke in Q/A Form!
@ -1101,7 +1211,10 @@ class Misc(commands.Cog):
None
"""
try:
(question, answer) = await self.util.get_qajoke()
qajoke: Optional[tuple] = await self.util.get_qajoke()
if not qajoke:
return
(question, answer) = qajoke
escaped_question = discord.utils.escape_markdown(question)
escasped_answer = discord.utils.escape_markdown(answer)
embed: discord.Embed = discord.Embed(title=escaped_question,
@ -1110,8 +1223,8 @@ class Misc(commands.Cog):
except Exception as e:
await ctx.respond(f"Error: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def rjoke(self, ctx) -> None:
"""
Get a joke! (from r/jokes scrape)
@ -1121,7 +1234,10 @@ class Misc(commands.Cog):
None
"""
try:
(title, body, score) = await self.util.get_rjoke()
rjoke: Optional[tuple] = await self.util.get_rjoke()
if not rjoke:
raise MiscException("Failed to get rjoke from db.")
(title, body, score) = rjoke
escaped_title = discord.utils.escape_markdown(title)
escaped_body = discord.utils.escape_markdown(body)
embed: discord.Embed = discord.Embed(title=escaped_title,
@ -1132,8 +1248,8 @@ class Misc(commands.Cog):
traceback.print_exc()
return await ctx.respond(f"Error: {str(e)}")
@bridge.bridge_command()
@is_spamchan_or_drugs() # pylint: disable=too-many-function-args
@bridge.bridge_command() # type: ignore
@is_spamchan_or_drugs()
async def joint(self, ctx, *,
recipient: Optional[str] = None) -> None:
"""
@ -1146,23 +1262,31 @@ class Misc(commands.Cog):
"""
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
else ctx.message.author.display_name
if recipient is None:
recipient: str = authorDisplay.strip()
if not recipient:
recipient = authorDisplay.strip()
recipient_normal: str = ctx.user.mention
else:
recipient_normal: str = recipient
recipient_normal = recipient
if discord.utils.raw_mentions(recipient):
# There are mentions
recipient_id: int = discord.utils.raw_mentions(recipient)[0] # First mention
recipient: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).display_name
recipient_normal: str = self.bot.get_guild(ctx.guild.id)\
.get_member(recipient_id).mention
guild: Optional[discord.Guild] = self.bot.get_guild(ctx.guild.id)
if not guild:
return
recipient_member: Optional[discord.Member] = guild.get_member(recipient_id)
if not recipient_member:
return
recipient = recipient_member.display_name
recipient_normal = recipient_member.mention
else:
recipient: str = discord.utils.escape_mentions(recipient.strip())
recipient = discord.utils.escape_mentions(recipient.strip())
try:
(choice_strain, choice_desc) = await self.util.get_strain()
strain: Optional[tuple] = await self.util.get_strain()
if not strain:
raise MiscException("Failed to get strain from db.")
(choice_strain, choice_desc) = strain
escaped_description = discord.utils.escape_markdown(choice_desc.strip())
await ctx.send_followup(f"*hands **{recipient_normal}** a joint rolled up with some **{choice_strain}***", username="Joint Granter")
embed: discord.Embed = discord.Embed(title=choice_strain,
@ -1239,8 +1363,8 @@ class Misc(commands.Cog):
""" User Commands """
@commands.user_command(name="Give Joint")
@is_spamchan() # pylint: disable=too-many-function-args
@commands.user_command(name="Give Joint") # type: ignore
@is_spamchan()
async def joint_context_menu(self, ctx, member: discord.Member) -> None:
"""
Joint Context Menu
@ -1250,7 +1374,10 @@ class Misc(commands.Cog):
Returns:
None
"""
(choice_strain, choice_desc) = await self.util.get_strain()
strain: Optional[tuple] = await self.util.get_strain()
if not strain:
raise MiscException("Failed to get strain from db.")
(choice_strain, choice_desc) = strain
escaped_desc = discord.utils.escape_markdown(choice_desc.strip())
await ctx.interaction.respond(f"*hands **<@{member.id}>** a joint rolled up with some **{choice_strain}***")
embed: discord.Embed = discord.Embed(title=choice_strain,
@ -1278,10 +1405,7 @@ class Misc(commands.Cog):
def cog_unload(self) -> None:
"""Run on Cog Unload"""
try:
self.randstat_loop.cancel()
except Exception as e:
logging.debug("Failed to cancel randstat loop: %s", str(e))
pass
def setup(bot) -> None:
"""Run on Cog Load"""