Various plugin updates. New plugin for stable diffusion

This commit is contained in:
Hash Borgir 2024-02-29 20:18:58 -07:00
parent 5962eb53ad
commit 542bb5d5cd
8 changed files with 59 additions and 3 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ simplematrixbotlib*/
chromedriver chromedriver
store store
funguybot.service funguybot.service
stats.db

View File

@ -58,7 +58,9 @@ async def handle_command(room, message, bot, prefix, config):
payload = response.json() payload = response.json()
new_text = payload['choices'][0]['text'] new_text = payload['choices'][0]['text']
new_text = markdown_to_html(new_text) new_text = markdown_to_html(new_text)
if new_text.count('<p>') > 2: # Check if new_text has more than one paragraph print(new_text)
if new_text.count('<p>') > 1 or new_text.count('<li>') > 1: # Check if new_text has more than one paragraph
#new_text = new_text.replace("\n", '<br>') #new_text = new_text.replace("\n", '<br>')
#new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text) #new_text = re.sub(r"\*\*(.*?)\*\*", r"<strong>\1</strong>", new_text)
new_text = "<details><summary><strong>🎵Funguy Music GPT🎵<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>" new_text = "<details><summary><strong>🎵Funguy Music GPT🎵<br>⤵Click Here To See Funguy's Response⤵</strong></summary>" + new_text + "</details>"

View File

@ -1,3 +1,6 @@
"""
Custom configuration class for the Funguy bot.
"""
# plugins/config.py # plugins/config.py
import os import os

View File

@ -1,3 +1,6 @@
"""
This plugin provides a command for the admin to load a plugin
"""
# plugins/load_plugin.py # plugins/load_plugin.py
import os import os

View File

@ -26,9 +26,9 @@ async def handle_command(room, message, bot, prefix, config):
plugin_descriptions = get_plugin_descriptions() plugin_descriptions = get_plugin_descriptions()
# Prepend custom string before the output # Prepend custom string before the output
plugin_descriptions.insert(0, "<details><summary><strong>🔌Plugins List🔌<br>⤵Click Here to Expand⤵</strong></summary><br>") plugin_descriptions.insert(0, "<details><summary><strong>🔌Plugins List🔌<br>⤵Click Here to Expand⤵</strong></summary>")
plugins_message = "<br><br>".join(plugin_descriptions) plugins_message = "<br>".join(plugin_descriptions)
plugins_message += "</details>" plugins_message += "</details>"
await bot.api.send_markdown_message(room.room_id, plugins_message) await bot.api.send_markdown_message(room.room_id, plugins_message)
logging.info("Sent plugin list to the room") logging.info("Sent plugin list to the room")

View File

@ -0,0 +1,42 @@
"""
This plugin provides a command to generate images using self hosted Stable Diffusion and send to the room
"""
# plugins/stable-diffusion.py
import requests
import base64
from asyncio import Queue
import simplematrixbotlib as botlib
# Queue to store pending commands
command_queue = Queue()
async def process_command(room, message, bot, prefix, config):
match = botlib.MessageMatch(room, message, bot, prefix)
if match.prefix() and match.command("sd"):
if command_queue.empty():
await handle_command(room, message, bot, prefix, config)
else:
await command_queue.put((room, message, bot, prefix, config))
async def handle_command(room, message, bot, prefix, config):
match = botlib.MessageMatch(room, message, bot, prefix)
if match.prefix() and match.command("sd"):
prompt = message.body[len(prefix) + len("sd"):].strip() # Extract prompt from message body
payload = {
"prompt": prompt,
"steps": 32
}
url = "http://127.0.0.1:7860/sdapi/v1/txt2img"
try:
response = requests.post(url=url, json=payload)
r = response.json()
with open("/tmp/output.png", 'wb') as f:
f.write(base64.b64decode(r['images'][0]))
await bot.api.send_image_message(room_id=room.room_id, image_filepath="/tmp/output.png") # Corrected argument name
except Exception as e:
await bot.api.send_text_message(room.room_id, f"Error processing the command: {str(e)}")
finally:
if not command_queue.empty():
next_command = await command_queue.get()
await handle_command(*next_command)

View File

@ -1,3 +1,6 @@
"""
This plugin provides a command to search for YouTube videos in the room
"""
# plugins/youtube_search.py # plugins/youtube_search.py
import logging import logging

View File

@ -4,3 +4,5 @@ pytube
duckduckgo_search duckduckgo_search
nio nio
markdown2 markdown2
watchdog
emoji