From 7b03b5fe6f8a3cda6bc66b96fc8d7e2a597a23bd Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Mon, 16 Jan 2023 03:15:47 +0000 Subject: [PATCH] all uncommitted changes --- skgyorugo/auto_messages/update_queue.py | 41 ++++++++++++++ skgyorugo/commands/9ball.py | 48 +++++++++++++++++ skgyorugo/commands/Q.py | 43 ++++++++++++--- skgyorugo/commands/cleanqueue.py | 36 +++++++++++-- skgyorugo/commands/forcehere.py | 70 ++++++++++++++++-------- skgyorugo/commands/forcejoin.py | 38 +++++++++++-- skgyorugo/commands/forceleave.py | 34 ++++++++++-- skgyorugo/commands/forcenothere.py | 34 ++++++++++-- skgyorugo/commands/here.py | 72 +++++++++++++++++-------- skgyorugo/commands/join.py | 40 +++++++++++--- skgyorugo/commands/leave.py | 34 ++++++++++-- skgyorugo/commands/movedown.py | 46 ++++++++++++---- skgyorugo/commands/moveup.py | 46 ++++++++++++---- skgyorugo/commands/newteams.py | 44 ++++++++++++--- skgyorugo/commands/nothere.py | 34 ++++++++++-- skgyorugo/commands/teams.py | 34 ++++++++++-- skgyorugo/commands/teamsize.py | 34 ++++++++++-- skgyorugo/main.py | 13 +++++ skgyorugo/scripts/alwase.py | 6 +-- skgyorugo/scripts/chat.py | 38 +++++++++++++ skgyorugo/scripts/chatting.py | 1 + skgyorugo/scripts/clean_queue.py | 19 +++++++ skgyorugo/scripts/clip_server.py | 38 +++++++++++++ skgyorugo/scripts/crylaugh.py | 16 ++++++ 24 files changed, 746 insertions(+), 113 deletions(-) create mode 100644 skgyorugo/auto_messages/update_queue.py create mode 100644 skgyorugo/commands/9ball.py create mode 100644 skgyorugo/scripts/chat.py create mode 100644 skgyorugo/scripts/clip_server.py create mode 100644 skgyorugo/scripts/crylaugh.py diff --git a/skgyorugo/auto_messages/update_queue.py b/skgyorugo/auto_messages/update_queue.py new file mode 100644 index 0000000..e7da3f9 --- /dev/null +++ b/skgyorugo/auto_messages/update_queue.py @@ -0,0 +1,41 @@ +import os +import sqlite3 +import time +from aptbot.bot import Message, Commands, Bot + +COOLDOWN = 60 +END_TIME = 0 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + + +def main(bot: Bot, message: Message): + conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) + c = conn.cursor() + + tables = ["lol_queue", "ow"] + + for table in tables: + c.execute( + f""" + UPDATE + {table} + SET + last_available = ?, + time_remaining = time_remaining - (? - last_available) + WHERE + available = 0; + """, + ( + int(time.time()), + int(time.time()), + ), + ) + c.execute(f"DELETE FROM {table} WHERE time_remaining < 0;") + if c.rowcount: + bot.send_privmsg(message.channel, f"/announce {c.rowcount} user{'s were' if c.rowcount > 1 else ' was'} just removed from {table if table != 'lol_queue' else 'lol'} queue.") + + conn.commit() + + conn.close() diff --git a/skgyorugo/commands/9ball.py b/skgyorugo/commands/9ball.py new file mode 100644 index 0000000..cc8d056 --- /dev/null +++ b/skgyorugo/commands/9ball.py @@ -0,0 +1,48 @@ +from aptbot.bot import Message, Commands, Bot +import os +import tools.smart_privmsg +import openai +from openai.error import RateLimitError + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = "" +USER_COOLDOWN = 40 +GLOBAL_COOLDOWN = 20 + +openai.api_key = os.getenv("OPENAI_API") + +def main(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'] + + + try: + response = openai.Completion.create( + # model="davinci:ft-personal:9ball-2022-12-05-08-37-36", + model="davinci:ft-personal-2022-12-06-10-03-18", + prompt=f"9ball is an 8ball. 9ball answers your questions reluctantly with sarcastic and unhelpful responses.\n{message.nick}: {msg}\n\n###\n\n", + temperature=1, + max_tokens=60, + top_p=0.3, + frequency_penalty=0.5, + presence_penalty=0.0, + stop=[" END"], + ) + except RateLimitError: + tools.smart_privmsg.send_safe(bot, message.channel, "UwU Sowwy. The sevwews awe ovewloaded :( Twy again in a few minutes OwO", reply=replied_msg_id) + + print(response) + if response: + msg = response["choices"][0]["text"] + # msg = msg[:msg.find("#")] + else: + msg = "Sadge nothing was returned" + + tools.smart_privmsg.send_safe(bot, message.channel, msg, reply=replied_msg_id) + # bot.send_privmsg(message.channel, msg, reply=replied_msg_id) diff --git a/skgyorugo/commands/Q.py b/skgyorugo/commands/Q.py index b7f4fd0..897c07e 100644 --- a/skgyorugo/commands/Q.py +++ b/skgyorugo/commands/Q.py @@ -5,6 +5,7 @@ import ttv_api.users import sqlite3 import tools.smart_privmsg import random +import shlex logger = logging.getLogger(__name__) @@ -17,8 +18,7 @@ GLOBAL_COOLDOWN = 15 PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") - -def main(bot: Bot, message: Message): +def check_queue(bot: Bot, message: Message, table: str): if random.random() < 0.02: q = [ "https://imgur.com/d5qGioI", @@ -45,8 +45,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - SELECT twitch_id, priority_queue FROM lol_queue WHERE available = 1 ORDER BY position ASC; + f""" + SELECT twitch_id, priority_queue FROM {table} WHERE available = 1 ORDER BY position ASC; """ ) fetched = c.fetchall() @@ -74,8 +74,8 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) c.execute( - """ - SELECT data FROM lol_queue_data WHERE name = 'queuesize'; + f""" + SELECT data FROM {table}_data WHERE name = 'queuesize'; """ ) try: @@ -89,8 +89,8 @@ def main(bot: Bot, message: Message): ) c.execute( - """ - SELECT twitch_id FROM lol_queue WHERE available = 0 ORDER BY position ASC; + f""" + SELECT twitch_id FROM {table} WHERE available = 0 ORDER BY position ASC; """ ) fetched_unavailable = c.fetchall() @@ -136,3 +136,30 @@ def main(bot: Bot, message: Message): ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[0].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + check_queue(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/cleanqueue.py b/skgyorugo/commands/cleanqueue.py index b94131b..ed3d447 100644 --- a/skgyorugo/commands/cleanqueue.py +++ b/skgyorugo/commands/cleanqueue.py @@ -4,6 +4,7 @@ import logging import ttv_api.users import sqlite3 import time +import shlex logger = logging.getLogger(__name__) @@ -17,7 +18,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def clean_queue(bot: Bot, message: Message, table: str): twitch = ttv_api.users.get_users(user_logins=[message.channel]) if not twitch: bot.send_privmsg( @@ -31,12 +32,12 @@ def main(bot: Bot, message: Message): conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) c = conn.cursor() - c.execute("DELETE FROM lol_queue") + c.execute(f"DELETE FROM {table}") conn.commit() c.execute( - """ - INSERT INTO lol_queue ( + f""" + INSERT INTO {table} ( "twitch_id", "position", "available", @@ -61,3 +62,30 @@ def main(bot: Bot, message: Message): ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[0].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + clean_queue(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/forcehere.py b/skgyorugo/commands/forcehere.py index 6e7d263..0c27769 100644 --- a/skgyorugo/commands/forcehere.py +++ b/skgyorugo/commands/forcehere.py @@ -1,5 +1,6 @@ from aptbot.bot import Message, Commands, Bot import os +import shlex import logging import ttv_api.users import sqlite3 @@ -17,7 +18,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def force_here(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -34,9 +35,9 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ + f""" UPDATE - lol_queue + {table} SET position = ( CASE @@ -44,7 +45,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -54,7 +55,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -63,7 +64,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -78,7 +79,7 @@ def main(bot: Bot, message: Message): SELECT max(position) FROM - lol_queue + {table} WHERE priority_queue = 1 OR position <= ( @@ -88,7 +89,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -97,7 +98,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -110,9 +111,9 @@ def main(bot: Bot, message: Message): ) c.execute( - """ + f""" UPDATE - lol_queue + {table} SET available = 1, priority_queue = ( @@ -121,7 +122,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -131,7 +132,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -140,7 +141,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -156,7 +157,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -166,7 +167,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -175,7 +176,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -185,7 +186,7 @@ def main(bot: Bot, message: Message): SELECT max(position) FROM - lol_queue + {table} WHERE priority_queue = 1 OR position <= ( @@ -195,7 +196,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -204,7 +205,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -235,7 +236,7 @@ def main(bot: Bot, message: Message): conn.close() return conn.commit() - c.execute("DELETE FROM lol_queue WHERE time_remaining < 0;") + c.execute(f"DELETE FROM {table} WHERE time_remaining < 0;") if c.rowcount > 0: bot.send_privmsg( message.channel, @@ -252,3 +253,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + force_here(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/forcejoin.py b/skgyorugo/commands/forcejoin.py index 950138f..df60a98 100644 --- a/skgyorugo/commands/forcejoin.py +++ b/skgyorugo/commands/forcejoin.py @@ -1,4 +1,5 @@ from aptbot.bot import Message, Commands, Bot +import shlex import os import logging import ttv_api.users @@ -18,7 +19,7 @@ PATH = os.path.join(PATH, "..") DEFAULT_TIME_REMAINING = 60 * 60 -def main(bot: Bot, message: Message): +def force_join(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -35,8 +36,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - SELECT position FROM lol_queue ORDER BY position DESC; + f""" + SELECT position FROM {table} ORDER BY position DESC; """ ) @@ -47,8 +48,8 @@ def main(bot: Bot, message: Message): try: c.execute( - """ - INSERT INTO lol_queue ( + f""" + INSERT INTO {table} ( "twitch_id", "position", "available", @@ -79,3 +80,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + force_join(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/forceleave.py b/skgyorugo/commands/forceleave.py index 4ae7874..62cce65 100644 --- a/skgyorugo/commands/forceleave.py +++ b/skgyorugo/commands/forceleave.py @@ -3,6 +3,7 @@ import os import logging import ttv_api.users import sqlite3 +import shlex logger = logging.getLogger(__name__) @@ -16,7 +17,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def force_leave(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -33,8 +34,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - DELETE FROM lol_queue WHERE twitch_id = ?; + f""" + DELETE FROM {table} WHERE twitch_id = ?; """, (twitch_id,), ) @@ -53,3 +54,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + force_leave(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/forcenothere.py b/skgyorugo/commands/forcenothere.py index 68edb69..4944b66 100644 --- a/skgyorugo/commands/forcenothere.py +++ b/skgyorugo/commands/forcenothere.py @@ -4,6 +4,7 @@ import logging import ttv_api.users import sqlite3 import time +import shlex logger = logging.getLogger(__name__) @@ -17,7 +18,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def force_not_here(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -34,8 +35,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; + f""" + UPDATE {table} SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; """, ( int(time.time()), @@ -57,3 +58,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + force_not_here(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/here.py b/skgyorugo/commands/here.py index 31ceb1a..2002cb5 100644 --- a/skgyorugo/commands/here.py +++ b/skgyorugo/commands/here.py @@ -4,20 +4,21 @@ import logging import ttv_api.users import sqlite3 import time +import shlex logger = logging.getLogger(__name__) PERMISSION = 99 PREFIX = "?" DESCRIPTION = r"Makes yourself available in the list." -USER_COOLDOWN = 600 +USER_COOLDOWN = 10 GLOBAL_COOLDOWN = 0 PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def here(bot: Bot, message: Message, table: str): twitch = ttv_api.users.get_users(user_logins=[message.nick]) if not twitch: bot.send_privmsg( @@ -31,9 +32,9 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ + f""" UPDATE - lol_queue + {table} SET position = ( CASE @@ -41,7 +42,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -51,7 +52,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -60,7 +61,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -75,7 +76,7 @@ def main(bot: Bot, message: Message): SELECT max(position) FROM - lol_queue + {table} WHERE priority_queue = 1 OR position <= ( @@ -85,7 +86,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -94,7 +95,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -107,9 +108,9 @@ def main(bot: Bot, message: Message): ) c.execute( - """ + f""" UPDATE - lol_queue + {table} SET available = 1, priority_queue = ( @@ -118,7 +119,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -128,7 +129,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -137,7 +138,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -153,7 +154,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) < ( @@ -163,7 +164,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -172,7 +173,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -182,7 +183,7 @@ def main(bot: Bot, message: Message): SELECT max(position) FROM - lol_queue + {table} WHERE priority_queue = 1 OR position <= ( @@ -192,7 +193,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE available = 1 ORDER BY @@ -201,7 +202,7 @@ def main(bot: Bot, message: Message): SELECT data FROM - lol_queue_data + {table}_data WHERE name = 'queuesize' ) @@ -232,7 +233,7 @@ def main(bot: Bot, message: Message): conn.close() return conn.commit() - c.execute("DELETE FROM lol_queue WHERE time_remaining < 0;") + c.execute(f"DELETE FROM {table} WHERE time_remaining < 0;") if c.rowcount > 0: bot.send_privmsg( message.channel, @@ -249,3 +250,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + here(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/join.py b/skgyorugo/commands/join.py index 77ff305..8484186 100644 --- a/skgyorugo/commands/join.py +++ b/skgyorugo/commands/join.py @@ -3,13 +3,14 @@ import os import logging import ttv_api.users import sqlite3 +import shlex logger = logging.getLogger(__name__) PERMISSION = 99 PREFIX = "?" DESCRIPTION = r"Joins the queue to play the game with the streamer." -USER_COOLDOWN = 60 +USER_COOLDOWN = 10 GLOBAL_COOLDOWN = 0 PATH = os.path.dirname(os.path.realpath(__file__)) @@ -18,7 +19,7 @@ PATH = os.path.join(PATH, "..") DEFAULT_TIME_REMAINING = 60 * 60 -def main(bot: Bot, message: Message): +def join(bot: Bot, message: Message, table: str): twitch = ttv_api.users.get_users(user_logins=[message.nick]) if not twitch: bot.send_privmsg( @@ -32,8 +33,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - SELECT position FROM lol_queue ORDER BY position DESC; + f""" + SELECT position FROM {table} ORDER BY position DESC; """ ) @@ -44,8 +45,8 @@ def main(bot: Bot, message: Message): try: c.execute( - """ - INSERT INTO lol_queue ( + f""" + INSERT INTO {table} ( "twitch_id", "position", "available", @@ -76,3 +77,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[0].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + join(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/leave.py b/skgyorugo/commands/leave.py index 5cfcd32..ac7fefe 100644 --- a/skgyorugo/commands/leave.py +++ b/skgyorugo/commands/leave.py @@ -3,6 +3,7 @@ import os import logging import ttv_api.users import sqlite3 +import shlex logger = logging.getLogger(__name__) @@ -18,7 +19,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def leave(bot: Bot, message: Message, table: str): twitch = ttv_api.users.get_users(user_logins=[message.nick]) if not twitch: bot.send_privmsg( @@ -32,8 +33,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - DELETE FROM lol_queue WHERE twitch_id = ?; + f""" + DELETE FROM {table} WHERE twitch_id = ?; """, (twitch_id,), ) @@ -52,3 +53,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[0].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + leave(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/movedown.py b/skgyorugo/commands/movedown.py index b6d8f71..e64d3ed 100644 --- a/skgyorugo/commands/movedown.py +++ b/skgyorugo/commands/movedown.py @@ -3,6 +3,7 @@ import os import logging import ttv_api.users import sqlite3 +import shlex logger = logging.getLogger(__name__) @@ -16,7 +17,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def move_down(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -35,21 +36,21 @@ def main(bot: Bot, message: Message): try: c.execute( - """ + f""" UPDATE - lol_queue + {table} SET position = ( SELECT min(position) FROM - lol_queue + {table} WHERE position > ( SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -57,7 +58,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) - position @@ -67,13 +68,13 @@ def main(bot: Bot, message: Message): SELECT min(position) FROM - lol_queue + {table} WHERE position > ( SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -82,7 +83,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -101,3 +102,30 @@ def main(bot: Bot, message: Message): message.channel, "Successfully moved them down.", reply=message.tags["id"] ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + move_down(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/moveup.py b/skgyorugo/commands/moveup.py index 5c062c7..42b7f12 100644 --- a/skgyorugo/commands/moveup.py +++ b/skgyorugo/commands/moveup.py @@ -3,6 +3,7 @@ import os import logging import ttv_api.users import sqlite3 +import shlex logger = logging.getLogger(__name__) @@ -16,7 +17,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def move_up(bot: Bot, message: Message, table: str): twitch_name = message.tags.get("reply-parent-user-login", None) if not twitch_name: twitch_name = message.value.split(" ")[1] @@ -35,21 +36,21 @@ def main(bot: Bot, message: Message): try: c.execute( - """ + f""" UPDATE - lol_queue + {table} SET position = ( SELECT max(position) FROM - lol_queue + {table} WHERE position < ( SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -57,7 +58,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) - position @@ -67,13 +68,13 @@ def main(bot: Bot, message: Message): SELECT max(position) FROM - lol_queue + {table} WHERE position < ( SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -82,7 +83,7 @@ def main(bot: Bot, message: Message): SELECT position FROM - lol_queue + {table} WHERE twitch_id = ? ) @@ -101,3 +102,30 @@ def main(bot: Bot, message: Message): message.channel, "Successfully moved them up.", reply=message.tags["id"] ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + move_up(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/newteams.py b/skgyorugo/commands/newteams.py index cf70770..a7a3c64 100644 --- a/skgyorugo/commands/newteams.py +++ b/skgyorugo/commands/newteams.py @@ -4,6 +4,7 @@ import logging import ttv_api.users import sqlite3 import random +import shlex logger = logging.getLogger(__name__) @@ -17,13 +18,13 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def new_teams(bot: Bot, message: Message, table: str): conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) c = conn.cursor() c.execute( - """ - SELECT twitch_id FROM lol_queue WHERE available = 1 ORDER BY position ASC; + f""" + SELECT twitch_id FROM {table} WHERE available = 1 ORDER BY position ASC; """ ) fetched = c.fetchall() @@ -50,8 +51,8 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) c.execute( - """ - SELECT data FROM lol_queue_data WHERE name = 'queuesize'; + f""" + SELECT data FROM {table}_data WHERE name = 'queuesize'; """ ) fetched = c.fetchone() @@ -77,10 +78,10 @@ def main(bot: Bot, message: Message): blue_team: list[ttv_api.users.User] = queue_users[: queue_size // 2] red_team: list[ttv_api.users.User] = queue_users[queue_size // 2 :] - c.execute("UPDATE lol_queue SET team = NULL") - sql = f"UPDATE lol_queue SET team = 0 WHERE twitch_id IN ({(', ?' * (queue_size // 2))[2:]})" + c.execute(f"UPDATE {table} SET team = NULL") + sql = f"UPDATE {table} SET team = 0 WHERE twitch_id IN ({(', ?' * (queue_size // 2))[2:]})" c.execute(sql, tuple(user.user_id for user in blue_team)) - sql = f"UPDATE lol_queue SET team = 1 WHERE twitch_id IN ({(', ?' * (queue_size - queue_size // 2))[2:]})" + sql = f"UPDATE {table} SET team = 1 WHERE twitch_id IN ({(', ?' * (queue_size - queue_size // 2))[2:]})" c.execute(sql, tuple(user.user_id for user in red_team)) conn.commit() @@ -94,3 +95,30 @@ def main(bot: Bot, message: Message): ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + new_teams(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/nothere.py b/skgyorugo/commands/nothere.py index 2aca550..f82bb68 100644 --- a/skgyorugo/commands/nothere.py +++ b/skgyorugo/commands/nothere.py @@ -4,6 +4,7 @@ import logging import ttv_api.users import sqlite3 import time +import shlex logger = logging.getLogger(__name__) @@ -17,7 +18,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def not_here(bot: Bot, message: Message, table: str): twitch = ttv_api.users.get_users(user_logins=[message.nick]) if not twitch: bot.send_privmsg( @@ -31,8 +32,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - UPDATE lol_queue SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; + f""" + UPDATE {table} SET available = 0, priority_queue = null, last_available = ? WHERE twitch_id = ?; """, ( int(time.time()), @@ -54,3 +55,30 @@ def main(bot: Bot, message: Message): reply=message.tags["id"], ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + not_here(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/teams.py b/skgyorugo/commands/teams.py index b777934..c35e65b 100644 --- a/skgyorugo/commands/teams.py +++ b/skgyorugo/commands/teams.py @@ -4,6 +4,7 @@ import logging import ttv_api.users import sqlite3 import tools.smart_privmsg +import shlex logger = logging.getLogger(__name__) @@ -17,13 +18,13 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def teams(bot: Bot, message: Message, table: str): conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) c = conn.cursor() c.execute( - """ - SELECT twitch_id, team FROM lol_queue WHERE team in (0, 1); + f""" + SELECT twitch_id, team FROM {table} WHERE team in (0, 1); """ ) fetched = c.fetchall() @@ -81,3 +82,30 @@ def main(bot: Bot, message: Message): ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[1].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + teams(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/commands/teamsize.py b/skgyorugo/commands/teamsize.py index f50277e..ce910c5 100644 --- a/skgyorugo/commands/teamsize.py +++ b/skgyorugo/commands/teamsize.py @@ -2,6 +2,7 @@ from aptbot.bot import Message, Commands, Bot import os import logging import sqlite3 +import shlex logger = logging.getLogger(__name__) @@ -15,7 +16,7 @@ PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") -def main(bot: Bot, message: Message): +def team_size(bot: Bot, message: Message, table: str): replied_message = message.tags.get("reply-parent-msg-body", None) if replied_message: queue_size = message.value.split(" ")[2] @@ -35,8 +36,8 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ - REPLACE INTO lol_queue_data (name, data) VALUES ('queuesize', ?) + f""" + REPLACE INTO {table}_data (name, data) VALUES ('queuesize', ?) """, (queue_size,), ) @@ -49,3 +50,30 @@ def main(bot: Bot, message: Message): ) conn.close() + + +def parse(query): + query = query.split() + try: + if query[0].lower() in {"ow", "overwatch", "ow2", "overwatch2"}: + return {"--game": "ow"} + except: + pass + return {"--game": "lol_queue"} + d = dict() + for i in shlex.split(query): + try: + d[i.split('=')[0]] = i.split('=')[1] + except: + pass + return d + + +def scrub(table_name): + return ''.join(chr for chr in table_name if chr.isalnum() or chr == '_') + + +def main(bot: Bot, message: Message): + args = " ".join(message.value.split(" ")[1:]) + args = parse(args) + team_size(bot, message, scrub(args.get("--game", "lol_queue"))) diff --git a/skgyorugo/main.py b/skgyorugo/main.py index e8f7dab..f4116e1 100644 --- a/skgyorugo/main.py +++ b/skgyorugo/main.py @@ -11,6 +11,8 @@ import analyze_command import scripts.unit_converter import scripts.alwase import scripts.chatting +import scripts.chat +import scripts.crylaugh import database_manager import analyze_auto_message import time @@ -26,6 +28,8 @@ reload(analyze_command) reload(scripts.unit_converter) reload(scripts.alwase) reload(scripts.chatting) +reload(scripts.chat) +reload(scripts.crylaugh) reload(database_manager) reload(analyze_auto_message) @@ -132,5 +136,14 @@ def main(bot: Bot, message: Message): scripts.alwase.alwase(bot, message) scripts.chatting.chatting(bot, message) scripts.chatting.chatting_annoy(bot, message) + scripts.chat.chat(bot, message) + scripts.crylaugh.crylaugh(bot, message) + + # if message.command == Commands.PART: + # if message.nick in {'jelemar', 'flauenn', 'ihaspeks', 'blobin_wobin', 'officiallysp'}: + # bot.send_privmsg(message.channel, f"/announce {message.nick} has left chat") + # if message.command == Commands.JOIN: + # if message.nick in {'jelemar', 'flauenn', 'ihaspeks', 'blobin_wobin', 'officiallysp'}: + # bot.send_privmsg(message.channel, f"/announce {message.nick} has joined chat") tools.raid.raid(bot, message) diff --git a/skgyorugo/scripts/alwase.py b/skgyorugo/scripts/alwase.py index b44597c..8516720 100644 --- a/skgyorugo/scripts/alwase.py +++ b/skgyorugo/scripts/alwase.py @@ -11,9 +11,9 @@ def alwase(bot: Bot, message: Message): except KeyError: replied_msg_id = None msgs = [ - "It's alwase Madge", - "Why don't you spell it alwase? Madge", - "Spell it alwase or peepoArriveBan", + "It's ALWASE gigaMadge", + "Why don't you spell it ALWASE ? gigaMadge", + "Spell it ALWASE or peepoArriveBan", ] msg = random.choice(msgs) tools.smart_privmsg.send(bot, message, msg, reply=replied_msg_id) diff --git a/skgyorugo/scripts/chat.py b/skgyorugo/scripts/chat.py new file mode 100644 index 0000000..26dbd19 --- /dev/null +++ b/skgyorugo/scripts/chat.py @@ -0,0 +1,38 @@ +from aptbot.bot import Message, Commands, Bot +import tools.smart_privmsg +import openai +import os + +openai.api_key = os.getenv("OPENAI_API") + +def chat(bot: Bot, message: Message): + if not message.nick in {'skgyorugo', 'ihaspeks'}: + return + if not message.value.startswith("# "): + return + + 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 = openai.Completion.create( + model="text-davinci-003", + prompt=msg, + temperature=1, + max_tokens=4000, + top_p=0.3, + frequency_penalty=0.5, + presence_penalty=0.5, + ) + + if response: + msg = response["choices"][0]["text"] + msg = msg.replace("\n", " ") + else: + msg = "Sadge nothing was returned" + + tools.smart_privmsg.send(bot, message, msg, reply=replied_msg_id) diff --git a/skgyorugo/scripts/chatting.py b/skgyorugo/scripts/chatting.py index 104094e..0eb7224 100644 --- a/skgyorugo/scripts/chatting.py +++ b/skgyorugo/scripts/chatting.py @@ -24,4 +24,5 @@ def chatting_annoy(bot: Bot, message: Message): if message.nick.lower() not in nicks: return msg = "Chatting " + message.value + # msg = "Pepelaff " + message.value tools.smart_privmsg.send(bot, message, msg) diff --git a/skgyorugo/scripts/clean_queue.py b/skgyorugo/scripts/clean_queue.py index 635b2b9..b86d7f7 100644 --- a/skgyorugo/scripts/clean_queue.py +++ b/skgyorugo/scripts/clean_queue.py @@ -36,6 +36,7 @@ def clean_queue(): c = conn.cursor() c.execute("DELETE FROM lol_queue") + c.execute("DELETE FROM ow") conn.commit() c.execute( @@ -56,6 +57,24 @@ def clean_queue(): 9999999, ), ) + c.execute( + """ + INSERT INTO ow ( + "twitch_id", + "position", + "available", + "last_available", + "time_remaining" + ) VALUES (?, ?, ?, ?, ?); + """, + ( + twitch_id, + 0, + 1, + None, + 9999999, + ), + ) conn.commit() conn.close() diff --git a/skgyorugo/scripts/clip_server.py b/skgyorugo/scripts/clip_server.py new file mode 100644 index 0000000..57d521b --- /dev/null +++ b/skgyorugo/scripts/clip_server.py @@ -0,0 +1,38 @@ +import os +import random +import sqlite3 +import logging +from fastapi import FastAPI +from fastapi.middleware.cors import CORSMiddleware + +app = FastAPI() + +origins = ["*"] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +@app.get("/clip") +async def root(): + clips = [ + "https://clips-media-assets2.twitch.tv/AT-cm%7CMGyhlrJbd3gtietAgP63LA.mp4", + "https://clips-media-assets2.twitch.tv/WATxq6O_aQBU1qrftJJ0fQ/AT-cm%7CWATxq6O_aQBU1qrftJJ0fQ.mp4", + ] + return random.choice(clips) + +# logger = logging.getLogger(__name__) + +# PATH = os.path.dirname(os.path.realpath(__file__)) +# logger.debug(f"PATH set to: {PATH}") + + +# def do_command(bot: Bot, message: Message, command_modules: dict): +# db_name_database = "database.db" +# conn = sqlite3.connect(os.path.join(PATH, db_name_database)) +# c = conn.cursor() +# logger.info(f"connected to database {db_name_database}") diff --git a/skgyorugo/scripts/crylaugh.py b/skgyorugo/scripts/crylaugh.py new file mode 100644 index 0000000..a6e2658 --- /dev/null +++ b/skgyorugo/scripts/crylaugh.py @@ -0,0 +1,16 @@ +from aptbot.bot import Bot, Message, Commands +import tools.smart_privmsg +import random + + +def crylaugh(bot: Bot, message: Message): + if random.random() > 0.05: + return + if "😂" not in message.value: + return + try: + replied_msg_id = message.tags["id"] + except KeyError: + replied_msg_id = None + msg = "Oh 😂 look 😂 at 😂 me 😂 I 😂 use 😂 this 😂 funny 😂 emoji 😂 hahahaha 😂😂😂😂😂 lit 💯 👌" + tools.smart_privmsg.send(bot, message, msg, reply=replied_msg_id) -- 2.30.2