cleanup / respect allergies
This commit is contained in:
parent
ac5da14632
commit
c682421570
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=broad-exception-caught, bare-except, invalid-name
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from os import path
|
from os import path
|
||||||
sys.path.append( path.dirname( path.dirname( path.abspath(__file__) ) ) )
|
sys.path.append( path.dirname( path.dirname( path.abspath(__file__) ) ) )
|
||||||
|
@ -1,15 +1,8 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=broad-exception-caught
|
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import logging
|
from typing import Optional, Union
|
||||||
import os
|
|
||||||
from typing import Any, Optional, Union
|
|
||||||
import discord
|
import discord
|
||||||
import aiosqlite as sqlite3
|
|
||||||
from discord.ext import bridge, commands
|
from discord.ext import bridge, commands
|
||||||
from util.lovehate_db import DB
|
from util.lovehate_db import DB
|
||||||
from constructors import LoveHateException
|
|
||||||
from disc_havoc import Havoc
|
from disc_havoc import Havoc
|
||||||
|
|
||||||
class LoveHate(commands.Cog):
|
class LoveHate(commands.Cog):
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
@ -25,7 +23,6 @@ import scrapers.dinosaur_scrape as dinog
|
|||||||
import scrapers.onion_scrape as oniong
|
import scrapers.onion_scrape as oniong
|
||||||
import scrapers.thn_scrape as thng
|
import scrapers.thn_scrape as thng
|
||||||
import constants
|
import constants
|
||||||
# pylint: disable=global-statement, bare-except, invalid-name, line-too-long
|
|
||||||
|
|
||||||
meme_choices = []
|
meme_choices = []
|
||||||
BOT_CHANIDS = []
|
BOT_CHANIDS = []
|
||||||
|
15
cogs/misc.py
15
cogs/misc.py
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
import urllib
|
import urllib
|
||||||
@ -14,8 +12,6 @@ from sh import cowsay as cow_say, fortune # pylint: disable=no-name-in-module
|
|||||||
from discord.ext import bridge, commands, tasks
|
from discord.ext import bridge, commands, tasks
|
||||||
from disc_havoc import Havoc
|
from disc_havoc import Havoc
|
||||||
from constructors import MiscException
|
from constructors import MiscException
|
||||||
# pylint: disable=bare-except, broad-exception-caught, broad-exception-raised, global-statement
|
|
||||||
# pylint: disable=too-many-lines, invalid-name
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This plugin encompasses numerous tiny commands/functions that
|
This plugin encompasses numerous tiny commands/functions that
|
||||||
@ -809,6 +805,8 @@ class Misc(commands.Cog):
|
|||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
recipient_allergic: bool = False
|
||||||
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
|
authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\
|
||||||
else ctx.message.author.display_name
|
else ctx.message.author.display_name
|
||||||
|
|
||||||
@ -831,7 +829,9 @@ class Misc(commands.Cog):
|
|||||||
else:
|
else:
|
||||||
recipient = discord.utils.escape_mentions(recipient.strip())
|
recipient = discord.utils.escape_mentions(recipient.strip())
|
||||||
try:
|
try:
|
||||||
chosen_coffee: Optional[str] = self.util.get_coffee()
|
if "pudding" in recipient or recipient_id in [898332028007751741]:
|
||||||
|
recipient_allergic = True
|
||||||
|
chosen_coffee: Optional[str] = self.util.get_coffee(recipient_allergic)
|
||||||
if not chosen_coffee:
|
if not chosen_coffee:
|
||||||
return
|
return
|
||||||
response = await ctx.respond(f"*hands **{recipient_normal}** {chosen_coffee}*")
|
response = await ctx.respond(f"*hands **{recipient_normal}** {chosen_coffee}*")
|
||||||
@ -1435,7 +1435,10 @@ class Misc(commands.Cog):
|
|||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
chosen_coffee = self.util.get_coffee()
|
recipient_allergic: bool = False
|
||||||
|
if member.id in [898332028007751741]:
|
||||||
|
recipient_allergic = True
|
||||||
|
chosen_coffee = self.util.get_coffee(recipient_allergic)
|
||||||
response = await ctx.interaction.respond(f"*hands <@{member.id}> {chosen_coffee}*")
|
response = await ctx.interaction.respond(f"*hands <@{member.id}> {chosen_coffee}*")
|
||||||
await self.util.increment_counter("coffees")
|
await self.util.increment_counter("coffees")
|
||||||
try:
|
try:
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
@ -380,17 +378,22 @@ class Util:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_coffee(self) -> Optional[str]:
|
def get_coffee(self,
|
||||||
|
recipient_allergic: Optional[bool] = False) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
Get Coffee
|
Get Coffee
|
||||||
|
|
||||||
|
Args:
|
||||||
|
recipient_allergic (bool): Is the recipient allergic? (so we know when to keep our nuts out of it)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
str
|
str
|
||||||
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
randomCoffee: str = random.choice(self.COFFEES)
|
randomCoffee: str = random.choice(self.COFFEES)
|
||||||
if self.LAST_5_COFFEES and randomCoffee in self.LAST_5_COFFEES:
|
if self.LAST_5_COFFEES and randomCoffee in self.LAST_5_COFFEES\
|
||||||
|
or (recipient_allergic and "nut" in randomCoffee.lower()):
|
||||||
return self.get_coffee() # Recurse
|
return self.get_coffee() # Recurse
|
||||||
if len(self.LAST_5_COFFEES) >= 5:
|
if len(self.LAST_5_COFFEES) >= 5:
|
||||||
self.LAST_5_COFFEES.pop() # Store no more than 5 of the last served coffees
|
self.LAST_5_COFFEES.pop() # Store no more than 5 of the last served coffees
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=bare-except, broad-exception-caught
|
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import random
|
import random
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -46,6 +43,34 @@ class Owner(commands.Cog):
|
|||||||
self._temperature = _temperature
|
self._temperature = _temperature
|
||||||
return await ctx.respond(f"As per your request, I have adjusted the temperature to {_temperature} °C.")
|
return await ctx.respond(f"As per your request, I have adjusted the temperature to {_temperature} °C.")
|
||||||
|
|
||||||
|
@bridge.bridge_command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def editmsg(self, ctx,
|
||||||
|
msgid: str,
|
||||||
|
*,
|
||||||
|
newcontent: str
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Edit a message previously sent by the bot
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ctx (Any): Discord context
|
||||||
|
msgid (str): Should be an int, the message id to edit
|
||||||
|
newcontent (str): Content to replace message with
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
message: Optional[discord.Message] = self.bot.get_message(int(msgid))
|
||||||
|
if not message:
|
||||||
|
await ctx.respond(f"**Failed:** Message {msgid} not found.",
|
||||||
|
ephemeral=True)
|
||||||
|
return None
|
||||||
|
await message.edit(content=newcontent)
|
||||||
|
await ctx.respond("**Done!**", ephemeral=True)
|
||||||
|
except Exception as e:
|
||||||
|
await ctx.respond(f"**Failed:** {str(e)}",
|
||||||
|
ephemeral=True)
|
||||||
|
|
||||||
@bridge.bridge_command()
|
@bridge.bridge_command()
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def reload(self, ctx) -> None:
|
async def reload(self, ctx) -> None:
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=bare-except, broad-exception-caught, invalid-name
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
30
cogs/sing.py
30
cogs/sing.py
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=bare-except, broad-exception-caught, global-statement, invalid-name
|
|
||||||
|
|
||||||
import traceback
|
import traceback
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
@ -12,7 +9,6 @@ from util.sing_util import Utility
|
|||||||
from discord.ext import bridge, commands
|
from discord.ext import bridge, commands
|
||||||
from disc_havoc import Havoc
|
from disc_havoc import Havoc
|
||||||
|
|
||||||
|
|
||||||
BOT_CHANIDS = []
|
BOT_CHANIDS = []
|
||||||
|
|
||||||
class Sing(commands.Cog):
|
class Sing(commands.Cog):
|
||||||
@ -73,11 +69,15 @@ class Sing(commands.Cog):
|
|||||||
(search_artist, search_song, search_subsearch) = parsed
|
(search_artist, search_song, search_subsearch) = parsed
|
||||||
|
|
||||||
# await ctx.respond(f"So, {search_song} by {search_artist}? Subsearch: {search_subsearch} I will try...") # Commented, useful for debugging
|
# await ctx.respond(f"So, {search_song} by {search_artist}? Subsearch: {search_subsearch} I will try...") # Commented, useful for debugging
|
||||||
search_result: list[str] = await self.utility.lyric_search(search_artist, search_song,
|
search_result: Optional[list] = await self.utility.lyric_search(search_artist, search_song,
|
||||||
search_subsearch)
|
search_subsearch)
|
||||||
|
|
||||||
|
if not search_result:
|
||||||
|
await ctx.respond("ERR: No search result.")
|
||||||
|
return
|
||||||
|
|
||||||
if len(search_result) == 1:
|
if len(search_result) == 1:
|
||||||
return await ctx.respond(search_result[0].strip())
|
return await ctx.respond("ERR: Not found!")
|
||||||
if not isinstance(search_result[0], tuple):
|
if not isinstance(search_result[0], tuple):
|
||||||
return # Invalid data type
|
return # Invalid data type
|
||||||
(
|
(
|
||||||
@ -111,11 +111,12 @@ class Sing(commands.Cog):
|
|||||||
embed.set_footer(text=footer)
|
embed.set_footer(text=footer)
|
||||||
embeds.append(embed)
|
embeds.append(embed)
|
||||||
await ctx.respond(embed=embeds[0])
|
await ctx.respond(embed=embeds[0])
|
||||||
for embed in embeds[1:]:
|
for _embed in embeds[1:]:
|
||||||
await ctx.send(embed=embed)
|
if isinstance(_embed, discord.Embed):
|
||||||
|
await ctx.send(embed=_embed)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return await ctx.respond(f"ERR: {str(e)}")
|
await ctx.respond(f"ERR: {str(e)}")
|
||||||
|
|
||||||
@commands.user_command(name="Sing")
|
@commands.user_command(name="Sing")
|
||||||
async def sing_context_menu(self, ctx, member: discord.Member) -> None:
|
async def sing_context_menu(self, ctx, member: discord.Member) -> None:
|
||||||
@ -151,15 +152,18 @@ class Sing(commands.Cog):
|
|||||||
if isinstance(parsed, tuple):
|
if isinstance(parsed, tuple):
|
||||||
(search_artist, search_song, search_subsearch) = parsed
|
(search_artist, search_song, search_subsearch) = parsed
|
||||||
await ctx.respond("*Searching...*", ephemeral=True) # Must respond to interactions within 3 seconds, per Discord
|
await ctx.respond("*Searching...*", ephemeral=True) # Must respond to interactions within 3 seconds, per Discord
|
||||||
search_result: list = await self.utility.lyric_search(search_artist, search_song,
|
search_result: Optional[list] = await self.utility.lyric_search(search_artist, search_song,
|
||||||
search_subsearch)
|
search_subsearch)
|
||||||
|
if not search_result:
|
||||||
|
await ctx.respond("ERR: No search result")
|
||||||
|
return
|
||||||
|
|
||||||
if len(search_result) == 1:
|
if isinstance(search_result[0], str):
|
||||||
return await ctx.send(search_result[0].strip())
|
return await ctx.send("ERR: No search result") # Error message from API
|
||||||
|
|
||||||
(search_result_artist, search_result_song, search_result_src,
|
(search_result_artist, search_result_song, search_result_src,
|
||||||
search_result_confidence, search_result_time_taken) = search_result[0] # First index is a tuple
|
search_result_confidence, search_result_time_taken) = search_result[0] # First index is a tuple
|
||||||
search_result_wrapped: list[str] = search_result[1] # Second index is the wrapped lyrics
|
search_result_wrapped: list = search_result[1] # Second index is the wrapped lyrics
|
||||||
search_result_wrapped_short: list[str] = search_result[2] # Third index is shortened lyrics
|
search_result_wrapped_short: list[str] = search_result[2] # Third index is shortened lyrics
|
||||||
|
|
||||||
if not IS_SPAMCHAN:
|
if not IS_SPAMCHAN:
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
AI
|
AI
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
# pylint: disable=bare-except, invalid-name, import-outside-toplevel
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import importlib
|
import importlib
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Tests for both Catbox & Litterbox
|
Tests for both Catbox & Litterbox
|
||||||
"""
|
"""
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
|
||||||
from . import discord_helpers
|
from . import discord_helpers
|
||||||
|
|
||||||
importlib.reload(discord_helpers)
|
importlib.reload(discord_helpers)
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from aiohttp import ClientSession, ClientTimeout, FormData
|
from aiohttp import ClientSession, ClientTimeout, FormData
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
import re
|
import re
|
||||||
import discord
|
import discord
|
||||||
from typing import Optional, Any
|
from typing import Optional, Any
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import regex
|
import regex
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Litterbox (Catbox) Uploader (Async)
|
Litterbox (Catbox) Uploader (Async)
|
||||||
"""
|
"""
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from typing import LiteralString, Optional, Union
|
from typing import LiteralString, Optional, Union
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from aiohttp import ClientSession, ClientTimeout
|
from aiohttp import ClientSession, ClientTimeout
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/usr/bin/env python3.12
|
|
||||||
import logging
|
import logging
|
||||||
import regex
|
import regex
|
||||||
import aiohttp
|
import aiohttp
|
||||||
@ -10,7 +9,7 @@ from typing import Optional, Union
|
|||||||
class Utility:
|
class Utility:
|
||||||
"""Sing Utility"""
|
"""Sing Utility"""
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.api_url: str = "http://127.0.0.1:52111/lyric/search"
|
self.api_url: str = "http://10.10.10.100:52111/lyric/search"
|
||||||
self.api_src: str = "DISC-HAVOC"
|
self.api_src: str = "DISC-HAVOC"
|
||||||
|
|
||||||
def parse_song_input(self, song: Optional[str] = None,
|
def parse_song_input(self, song: Optional[str] = None,
|
||||||
@ -120,7 +119,7 @@ class Utility:
|
|||||||
if response.get('err'):
|
if response.get('err'):
|
||||||
return [(f"ERR: {response.get('errorText')}",)]
|
return [(f"ERR: {response.get('errorText')}",)]
|
||||||
|
|
||||||
out_lyrics = regex.sub(r'<br>', '\u200B\n', response.get('lyrics'))
|
out_lyrics = regex.sub(r'<br>', '\u200B\n', response.get('lyrics', ''))
|
||||||
response_obj: dict = {
|
response_obj: dict = {
|
||||||
'artist': response.get('artist'),
|
'artist': response.get('artist'),
|
||||||
'song': response.get('song'),
|
'song': response.get('song'),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user