logger.debug(f"PATH set to: {PATH}")
-def do_command(bot: Bot, message: Message, command_modules: dict):
+def do_command(bot: Bot, message: Message, command_modules: dict) -> bool:
db_name_database = "database.db"
conn = sqlite3.connect(os.path.join(PATH, db_name_database))
c = conn.cursor()
fetched = c.fetchall()
if not fetched:
conn.close()
- return
+ return False
(
_,
Please wait {int(avail_time - message_timestamp) + 1} seconds.",
)
conn.close()
- return
+ return False
c.execute(
"REPLACE INTO cooldowns VALUES (?, ?, ?)",
command_modules[command].main(bot, message)
else:
tools.smart_privmsg.send(bot, message, value)
+
+ return True
import scripts.clean_queue
import scripts.discord_start_stream
import scripts.will_be_missed
+import scripts.command_generator
import database_manager
import analyze_auto_message
import time
reload(scripts.clean_queue)
reload(scripts.discord_start_stream)
reload(scripts.will_be_missed)
+reload(scripts.command_generator)
reload(database_manager)
reload(analyze_auto_message)
if message.command == Commands.PRIVMSG:
database_manager.add_message_to_chat_history(message)
if message.value[0] in {"?", "\\"}:
- analyze_command.do_command(bot, message, commands_modules)
+ if not analyze_command.do_command(bot, message, commands_modules):
+ scripts.command_generator.generate(bot, message)
scripts.unit_converter.send_metric(bot, message)
scripts.alwase.alwase(bot, message)
scripts.alwase.no_horny(bot, message)
--- /dev/null
+from aptbot.bot import Bot, Message, Commands
+import os
+import tools.smart_privmsg
+import requests
+
+openai_api_key = os.getenv("OPENAI_API")
+
+SYSTEM_CONTENT = """You act like a twitch.tv command. The user gives you a word and you say something that would be expected to be said as that word being a command. All words are valid commands.
+
+Do not comment about what's going to happen on stream. Do not add <insert X> type of text.
+
+All commands start with a question mark. Every word is a valid command. Come up with something funny.
+
+Some information: The name of the streamer is Peks. His avatar is a shiba inu doge. He likes playing League of Legends and Overwatch 2. He mains Twitch in League of Legends and Genji in Overwatch 2. He's born in England, but has lived in France since he was 4, so Peks is French.
+
+Try to come up with funny and troll answers. Stuff that would annoy viewers."""
+
+
+def generate(bot: Bot, message: Message):
+ replied_message = message.tags.get("reply-parent-msg-body", None)
+ if replied_message:
+ msg = replied_message
+ replied_msg_id = message.tags["reply-parent-msg-id"]
+ else:
+ msg = " ".join(message.value.split(" ")[1:])
+ replied_msg_id = message.tags["id"]
+
+ response = requests.post(
+ "https://api.openai.com/v1/chat/completions",
+ headers={
+ "Content-Type": "application/json",
+ "Authorization": f"Bearer {openai_api_key}",
+ },
+ data={
+ "model": "gpt-3.5-turbo",
+ "messages": [
+ {
+ "role": "system",
+ "content": SYSTEM_CONTENT,
+ },
+ {
+ "role": "user",
+ "content": msg,
+ }
+ ],
+ },
+ )
+ print(response)
+ if response.status_code != 200:
+ msg = "Sowwy, theres a minor issue right now :("
+ else:
+ msg = response.json()["choices"][0]["message"]["content"]
+
+ tools.smart_privmsg.send_safe(bot, message.channel, msg, reply=replied_msg_id)