mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 01:06:19 +00:00
fix(requirements.txt): add bs4 package to requirements.txt for BeautifulSoup usage
feat(functionscalls.py): add new functions send_ascii_art_text and send_ascii_art_image to send messages and images in ascii art fix(makeprompt.py): import send_ascii_art_text and send_ascii_art_image functions and add corresponding if statements to handle function calls
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import discord
|
||||
import aiohttp
|
||||
import random
|
||||
|
||||
import time
|
||||
from bs4 import BeautifulSoup
|
||||
from src.config import tenor_api_key
|
||||
|
||||
randomseed = time.time()
|
||||
random.seed(randomseed)
|
||||
tenor_api_url = f"https://tenor.googleapis.com/v2/search?key={tenor_api_key}&q="
|
||||
|
||||
functions = [
|
||||
@@ -73,6 +75,46 @@ functions = [
|
||||
"required": ["query"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "send_ascii_art_text",
|
||||
"description": "Sendsa message in huge ascii art text.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string",
|
||||
"description": "The text to send as ascii art",
|
||||
},
|
||||
"font": {
|
||||
"type": "string",
|
||||
"description": "The font to use, between 'standard'(default), 'shadow', 'money' (made out of $), 'bloody', 'dos-rebel'(like in the matrix, a really cool one). Remember to use this with not too long text (max 5 characters), otherwise it will look weird. To send multiple max 5 length word, add line breaks between them.",
|
||||
},
|
||||
"message": {
|
||||
"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.",
|
||||
}
|
||||
},
|
||||
"required": ["text"],
|
||||
},
|
||||
},
|
||||
{
|
||||
"name": "send_ascii_art_image",
|
||||
"description": "Sends an image in ascii art.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"query": {
|
||||
"type": "string",
|
||||
"description": "The query to search for, words separated by spaces, max 2 words",
|
||||
},
|
||||
"message": {
|
||||
"type": "string",
|
||||
"description": "Your message to send with the image",
|
||||
}
|
||||
},
|
||||
"required": ["query"],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
server_normal_channel_functions = [
|
||||
@@ -93,6 +135,14 @@ server_normal_channel_functions = [
|
||||
},
|
||||
]
|
||||
|
||||
font_matches = {
|
||||
"standard": "ANSI Regular",
|
||||
"shadow": "ANSI Shadow",
|
||||
"money": random.choice(["Big Money-ne", "Big Money-nw", "Big Money-se", "Big Money-sw"]),
|
||||
"bloody": "Bloody",
|
||||
"dos-rebel": "DOS Rebel",
|
||||
}
|
||||
|
||||
unsplash_random_image_url = "https://source.unsplash.com/random"
|
||||
|
||||
|
||||
@@ -102,10 +152,14 @@ async def get_final_url(url):
|
||||
final_url = str(response.url)
|
||||
return final_url
|
||||
|
||||
async def do_async_request(url):
|
||||
async def do_async_request(url, json=True):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get(url) as response:
|
||||
response = await response.json()
|
||||
|
||||
if json:
|
||||
response = await response.json()
|
||||
else:
|
||||
response = await response.text()
|
||||
return response
|
||||
|
||||
async def add_reaction_to_last_message(
|
||||
@@ -145,6 +199,25 @@ async def send_a_gif(message_in_channel_in_wich_to_send: discord.Message, query:
|
||||
response = await do_async_request(image_url)
|
||||
json = response
|
||||
print(json)
|
||||
gif_url = random.choice(json["results"])["itemurl"]
|
||||
gif_url = random.choice(json["results"])["itemurl"] # type: ignore
|
||||
message = message + "\n" + gif_url
|
||||
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 = ""):
|
||||
font = font_matches[font]
|
||||
text = text.replace(" ", "+")
|
||||
asciiiar_url = f"https://asciified.thelicato.io/api?text={text}&font={font}"
|
||||
response = await do_async_request(asciiiar_url, json=False)
|
||||
message = f"```\n{response}```\n{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 = ""):
|
||||
query = query.replace(" ", "-")
|
||||
asciiiar_url = f"https://emojicombos.com/{query}"
|
||||
response = await do_async_request(asciiiar_url, json=False)
|
||||
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 = [combo["data-combo"] for combo in combos if len(combo["data-combo"]) <= 2000]
|
||||
combo = random.choice(combos)
|
||||
message = f"```\n{combo}```\n{message}"
|
||||
await message_in_channel_in_wich_to_send.channel.send(message)
|
||||
Reference in New Issue
Block a user