cleanup / respect allergies
This commit is contained in:
		| @@ -1,6 +1,3 @@ | ||||
| #!/usr/bin/env python3.12 | ||||
| # pylint: disable=broad-exception-caught, bare-except, invalid-name | ||||
|  | ||||
| import sys | ||||
| from os import path | ||||
| 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 logging | ||||
| import os | ||||
| from typing import Any, Optional, Union | ||||
| from typing import Optional, Union | ||||
| import discord | ||||
| import aiosqlite as sqlite3 | ||||
| from discord.ext import bridge, commands | ||||
| from util.lovehate_db import DB | ||||
| from constructors import LoveHateException | ||||
| from disc_havoc import Havoc | ||||
|  | ||||
| class LoveHate(commands.Cog): | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| #!/usr/bin/env python3.12 | ||||
|  | ||||
| import os | ||||
| import traceback | ||||
| import json | ||||
| @@ -25,7 +23,6 @@ import scrapers.dinosaur_scrape as dinog | ||||
| import scrapers.onion_scrape as oniong | ||||
| import scrapers.thn_scrape as thng | ||||
| import constants | ||||
| # pylint: disable=global-statement, bare-except, invalid-name, line-too-long | ||||
|  | ||||
| meme_choices = [] | ||||
| BOT_CHANIDS = [] | ||||
|   | ||||
							
								
								
									
										15
									
								
								cogs/misc.py
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cogs/misc.py
									
									
									
									
									
								
							| @@ -1,5 +1,3 @@ | ||||
| #!/usr/bin/env python3.12 | ||||
|  | ||||
| import os | ||||
| import traceback | ||||
| 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 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 | ||||
|  | ||||
| """ | ||||
| This plugin encompasses numerous tiny commands/functions that | ||||
| @@ -809,6 +805,8 @@ class Misc(commands.Cog): | ||||
|         Returns: | ||||
|             None | ||||
|         """ | ||||
|          | ||||
|         recipient_allergic: bool = False | ||||
|         authorDisplay: str = ctx.author.display_name if not(ctx.author.display_name is None)\ | ||||
|             else ctx.message.author.display_name | ||||
|  | ||||
| @@ -831,7 +829,9 @@ class Misc(commands.Cog): | ||||
|             else: | ||||
|                 recipient = discord.utils.escape_mentions(recipient.strip()) | ||||
|         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: | ||||
|                 return | ||||
|             response = await ctx.respond(f"*hands **{recipient_normal}** {chosen_coffee}*")             | ||||
| @@ -1435,7 +1435,10 @@ class Misc(commands.Cog): | ||||
|         Returns: | ||||
|             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}*") | ||||
|         await self.util.increment_counter("coffees") | ||||
|         try: | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| #!/usr/bin/env python3.12 | ||||
|  | ||||
| import os | ||||
| import logging | ||||
| 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 | ||||
|          | ||||
|         Args: | ||||
|             recipient_allergic (bool): Is the recipient allergic? (so we know when to keep our nuts out of it) | ||||
|          | ||||
|         Returns: | ||||
|             str | ||||
|              | ||||
|         """ | ||||
|         try: | ||||
|             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 | ||||
|             if len(self.LAST_5_COFFEES) >= 5: | ||||
|                 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 random | ||||
| import asyncio | ||||
| @@ -45,6 +42,34 @@ class Owner(commands.Cog): | ||||
|             return await ctx.respond("Too hot! (35°C maximum)") | ||||
|         self._temperature = _temperature | ||||
|         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() | ||||
|     @commands.is_owner() | ||||
|   | ||||
| @@ -1,6 +1,3 @@ | ||||
| #!/usr/bin/env python3.12 | ||||
| # pylint: disable=bare-except, broad-exception-caught, invalid-name | ||||
|  | ||||
| import logging | ||||
| import traceback | ||||
| from typing import Optional | ||||
|   | ||||
							
								
								
									
										32
									
								
								cogs/sing.py
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								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 logging | ||||
| from typing import Optional, Union | ||||
| @@ -12,7 +9,6 @@ from util.sing_util import Utility | ||||
| from discord.ext import bridge, commands | ||||
| from disc_havoc import Havoc | ||||
|  | ||||
|  | ||||
| BOT_CHANIDS = [] | ||||
|  | ||||
| class Sing(commands.Cog): | ||||
| @@ -73,11 +69,15 @@ class Sing(commands.Cog): | ||||
|                     (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 | ||||
|                 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) | ||||
|                  | ||||
|                 if not search_result: | ||||
|                     await ctx.respond("ERR: No search result.") | ||||
|                     return | ||||
|                  | ||||
|                 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): | ||||
|                     return # Invalid data type | ||||
|                 ( | ||||
| @@ -111,11 +111,12 @@ class Sing(commands.Cog): | ||||
|                     embed.set_footer(text=footer) | ||||
|                     embeds.append(embed) | ||||
|                 await ctx.respond(embed=embeds[0])     | ||||
|                 for embed in embeds[1:]: | ||||
|                     await ctx.send(embed=embed) | ||||
|                 for _embed in embeds[1:]: | ||||
|                     if isinstance(_embed, discord.Embed): | ||||
|                         await ctx.send(embed=_embed) | ||||
|         except Exception as e: | ||||
|             traceback.print_exc() | ||||
|             return await ctx.respond(f"ERR: {str(e)}") | ||||
|             await ctx.respond(f"ERR: {str(e)}") | ||||
|              | ||||
|     @commands.user_command(name="Sing") | ||||
|     async def sing_context_menu(self, ctx, member: discord.Member) -> None: | ||||
| @@ -151,15 +152,18 @@ class Sing(commands.Cog): | ||||
|             if isinstance(parsed, tuple): | ||||
|                 (search_artist, search_song, search_subsearch) = parsed | ||||
|                 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) | ||||
|              | ||||
|                 if len(search_result) == 1: | ||||
|                     return await ctx.send(search_result[0].strip())            | ||||
|                 if not search_result: | ||||
|                     await ctx.respond("ERR: No search result") | ||||
|                     return | ||||
|                  | ||||
|                 if isinstance(search_result[0], str): | ||||
|                     return await ctx.send("ERR: No search result") # Error message from API            | ||||
|                  | ||||
|                 (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_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 | ||||
|                  | ||||
|                 if not IS_SPAMCHAN: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user