diff --git a/.gitignore b/.gitignore index 83d7330..1056362 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ simplematrixbotlib*/ chromedriver store funguybot.service +stats.db \ No newline at end of file diff --git a/plugins/ai-music.py b/plugins/ai-music.py index 314bb0c..72c439b 100644 --- a/plugins/ai-music.py +++ b/plugins/ai-music.py @@ -58,7 +58,9 @@ async def handle_command(room, message, bot, prefix, config): payload = response.json() new_text = payload['choices'][0]['text'] new_text = markdown_to_html(new_text) - if new_text.count('

') > 2: # Check if new_text has more than one paragraph + print(new_text) + + if new_text.count('

') > 1 or new_text.count('

  • ') > 1: # Check if new_text has more than one paragraph #new_text = new_text.replace("\n", '
    ') #new_text = re.sub(r"\*\*(.*?)\*\*", r"\1", new_text) new_text = "
    🎵Funguy Music GPT🎵
    ⤵︎Click Here To See Funguy's Response⤵︎
    " + new_text + "
    " diff --git a/plugins/config.py b/plugins/config.py index d71ce31..e8dbe39 100644 --- a/plugins/config.py +++ b/plugins/config.py @@ -1,3 +1,6 @@ +""" +Custom configuration class for the Funguy bot. +""" # plugins/config.py import os diff --git a/plugins/loadplugin.py b/plugins/loadplugin.py index 2c650f3..57b968e 100644 --- a/plugins/loadplugin.py +++ b/plugins/loadplugin.py @@ -1,3 +1,6 @@ +""" +This plugin provides a command for the admin to load a plugin +""" # plugins/load_plugin.py import os diff --git a/plugins/plugins.py b/plugins/plugins.py index 9a9baf8..a407b8f 100644 --- a/plugins/plugins.py +++ b/plugins/plugins.py @@ -26,9 +26,9 @@ async def handle_command(room, message, bot, prefix, config): plugin_descriptions = get_plugin_descriptions() # Prepend custom string before the output - plugin_descriptions.insert(0, "
    🔌Plugins List🔌
    ⤵︎Click Here to Expand⤵︎

    ") + plugin_descriptions.insert(0, "
    🔌Plugins List🔌
    ⤵︎Click Here to Expand⤵︎
    ") - plugins_message = "

    ".join(plugin_descriptions) + plugins_message = "
    ".join(plugin_descriptions) plugins_message += "
    " await bot.api.send_markdown_message(room.room_id, plugins_message) logging.info("Sent plugin list to the room") diff --git a/plugins/stable-diffusion.py b/plugins/stable-diffusion.py new file mode 100644 index 0000000..dcf1186 --- /dev/null +++ b/plugins/stable-diffusion.py @@ -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) + diff --git a/plugins/youtube-search.py b/plugins/youtube-search.py index 0da073b..bb209aa 100644 --- a/plugins/youtube-search.py +++ b/plugins/youtube-search.py @@ -1,3 +1,6 @@ +""" +This plugin provides a command to search for YouTube videos in the room +""" # plugins/youtube_search.py import logging diff --git a/requirements.txt b/requirements.txt index b22b413..329a2a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ pytube duckduckgo_search nio markdown2 +watchdog +emoji