Format with black

This commit is contained in:
Paillat
2023-07-18 23:23:47 +02:00
parent a9f85e9ac9
commit 98195b29e3
2 changed files with 33 additions and 11 deletions

View File

@@ -23,6 +23,7 @@ os.environ[
# Defining a debug function # Defining a debug function
def debug(message): def debug(message):
if os.name == "nt": if os.name == "nt":
logging.info(message) logging.info(message)

View File

@@ -4,6 +4,7 @@ import random
import time import time
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from src.config import tenor_api_key from src.config import tenor_api_key
randomseed = time.time() randomseed = time.time()
random.seed(randomseed) random.seed(randomseed)
tenor_api_url = f"https://tenor.googleapis.com/v2/search?key={tenor_api_key}&q=" tenor_api_url = f"https://tenor.googleapis.com/v2/search?key={tenor_api_key}&q="
@@ -92,7 +93,7 @@ functions = [
"message": { "message": {
"type": "string", "type": "string",
"description": "Your message to send with the ascii art. It will not be converted to ascii art, just sent as a normal message.", "description": "Your message to send with the ascii art. It will not be converted to ascii art, just sent as a normal message.",
} },
}, },
"required": ["text"], "required": ["text"],
}, },
@@ -110,7 +111,7 @@ functions = [
"message": { "message": {
"type": "string", "type": "string",
"description": "Your message to send with the image", "description": "Your message to send with the image",
} },
}, },
"required": ["query"], "required": ["query"],
}, },
@@ -138,7 +139,9 @@ server_normal_channel_functions = [
font_matches = { font_matches = {
"standard": "ANSI Regular", "standard": "ANSI Regular",
"shadow": "ANSI Shadow", "shadow": "ANSI Shadow",
"money": random.choice(["Big Money-ne", "Big Money-nw", "Big Money-se", "Big Money-sw"]), "money": random.choice(
["Big Money-ne", "Big Money-nw", "Big Money-se", "Big Money-sw"]
),
"bloody": "Bloody", "bloody": "Bloody",
"dos-rebel": "DOS Rebel", "dos-rebel": "DOS Rebel",
} }
@@ -152,16 +155,17 @@ async def get_final_url(url):
final_url = str(response.url) final_url = str(response.url)
return final_url return final_url
async def do_async_request(url, json=True): async def do_async_request(url, json=True):
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(url) as response: async with session.get(url) as response:
if json: if json:
response = await response.json() response = await response.json()
else: else:
response = await response.text() response = await response.text()
return response return response
async def add_reaction_to_last_message( async def add_reaction_to_last_message(
message_to_react_to: discord.Message, emoji, message="" message_to_react_to: discord.Message, emoji, message=""
): ):
@@ -192,7 +196,13 @@ async def create_a_thread(
msg = await channel_in_which_to_create_the_thread.send(message) msg = await channel_in_which_to_create_the_thread.send(message)
await msg.create_thread(name=name) await msg.create_thread(name=name)
async def send_a_gif(message_in_channel_in_wich_to_send: discord.Message, query: str, message: str = "", limit: int = 15):
async def send_a_gif(
message_in_channel_in_wich_to_send: discord.Message,
query: str,
message: str = "",
limit: int = 15,
):
query = query.replace(" ", "+") query = query.replace(" ", "+")
image_url = f"{tenor_api_url}{query}&limit={limit}" image_url = f"{tenor_api_url}{query}&limit={limit}"
print(image_url) print(image_url)
@@ -203,7 +213,13 @@ async def send_a_gif(message_in_channel_in_wich_to_send: discord.Message, query:
message = message + "\n" + gif_url message = message + "\n" + gif_url
await message_in_channel_in_wich_to_send.channel.send(message) await message_in_channel_in_wich_to_send.channel.send(message)
async def send_ascii_art_text(message_in_channel_in_wich_to_send: discord.Message, text: str, font: str = "standard", message: str = ""):
async def send_ascii_art_text(
message_in_channel_in_wich_to_send: discord.Message,
text: str,
font: str = "standard",
message: str = "",
):
font = font_matches[font] font = font_matches[font]
text = text.replace(" ", "+") text = text.replace(" ", "+")
asciiiar_url = f"https://asciified.thelicato.io/api?text={text}&font={font}" asciiiar_url = f"https://asciified.thelicato.io/api?text={text}&font={font}"
@@ -211,13 +227,18 @@ async def send_ascii_art_text(message_in_channel_in_wich_to_send: discord.Messag
message = f"```\n{response}```\n{message}" message = f"```\n{response}```\n{message}"
await message_in_channel_in_wich_to_send.channel.send(message) await message_in_channel_in_wich_to_send.channel.send(message)
async def send_ascii_art_image(message_in_channel_in_wich_to_send: discord.Message, query: str, message: str = ""):
async def send_ascii_art_image(
message_in_channel_in_wich_to_send: discord.Message, query: str, message: str = ""
):
query = query.replace(" ", "-") query = query.replace(" ", "-")
asciiiar_url = f"https://emojicombos.com/{query}" asciiiar_url = f"https://emojicombos.com/{query}"
response = await do_async_request(asciiiar_url, json=False) response = await do_async_request(asciiiar_url, json=False)
soup = BeautifulSoup(response, "html.parser") soup = BeautifulSoup(response, "html.parser")
combos = soup.find_all("div", class_=lambda x: x and "combo-ctn" in x and "hidden" not in x)[:5] # type: ignore combos = soup.find_all("div", class_=lambda x: x and "combo-ctn" in x and "hidden" not in x)[:5] # type: ignore
combos = [combo["data-combo"] for combo in combos if len(combo["data-combo"]) <= 2000] combos = [
combo["data-combo"] for combo in combos if len(combo["data-combo"]) <= 2000
]
combo = random.choice(combos) combo = random.choice(combos)
message = f"```\n{combo}```\n{message}" message = f"```\n{combo}```\n{message}"
await message_in_channel_in_wich_to_send.channel.send(message) await message_in_channel_in_wich_to_send.channel.send(message)