mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 09:16: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:
@@ -6,3 +6,4 @@ emoji
|
|||||||
google-api-python-client
|
google-api-python-client
|
||||||
google-cloud-vision
|
google-cloud-vision
|
||||||
tiktoken
|
tiktoken
|
||||||
|
bs4
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import discord
|
import discord
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
from src.config import tenor_api_key
|
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="
|
tenor_api_url = f"https://tenor.googleapis.com/v2/search?key={tenor_api_key}&q="
|
||||||
|
|
||||||
functions = [
|
functions = [
|
||||||
@@ -73,6 +75,46 @@ functions = [
|
|||||||
"required": ["query"],
|
"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 = [
|
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"
|
unsplash_random_image_url = "https://source.unsplash.com/random"
|
||||||
|
|
||||||
|
|
||||||
@@ -102,10 +152,14 @@ 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):
|
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:
|
||||||
response = await response.json()
|
response = await response.json()
|
||||||
|
else:
|
||||||
|
response = await response.text()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def add_reaction_to_last_message(
|
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)
|
response = await do_async_request(image_url)
|
||||||
json = response
|
json = response
|
||||||
print(json)
|
print(json)
|
||||||
gif_url = random.choice(json["results"])["itemurl"]
|
gif_url = random.choice(json["results"])["itemurl"] # type: ignore
|
||||||
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 = ""):
|
||||||
|
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)
|
||||||
@@ -13,6 +13,8 @@ from src.functionscalls import (
|
|||||||
send_a_stock_image,
|
send_a_stock_image,
|
||||||
create_a_thread,
|
create_a_thread,
|
||||||
send_a_gif,
|
send_a_gif,
|
||||||
|
send_ascii_art_text,
|
||||||
|
send_ascii_art_image,
|
||||||
functions,
|
functions,
|
||||||
server_normal_channel_functions,
|
server_normal_channel_functions,
|
||||||
)
|
)
|
||||||
@@ -151,6 +153,17 @@ async def chatgpt_process(
|
|||||||
reply = arguments.get("message", "")
|
reply = arguments.get("message", "")
|
||||||
limit = arguments.get("limit", 15)
|
limit = arguments.get("limit", 15)
|
||||||
await send_a_gif(message, query, reply, limit)
|
await send_a_gif(message, query, reply, limit)
|
||||||
|
if name == "send_ascii_art_text":
|
||||||
|
if arguments.get("text"):
|
||||||
|
text = arguments.get("text")
|
||||||
|
font = arguments.get("font", "standard")
|
||||||
|
reply = arguments.get("message", "")
|
||||||
|
await send_ascii_art_text(message, text, font, reply)
|
||||||
|
if name == "send_ascii_art_image":
|
||||||
|
if arguments.get("query"):
|
||||||
|
query = arguments.get("query")
|
||||||
|
reply = arguments.get("message", "")
|
||||||
|
await send_ascii_art_image(message, query, reply)
|
||||||
if name == "":
|
if name == "":
|
||||||
await message.channel.send(
|
await message.channel.send(
|
||||||
"The function call is empty. Please retry.", delete_after=10
|
"The function call is empty. Please retry.", delete_after=10
|
||||||
|
|||||||
Reference in New Issue
Block a user