From: Georgios Atheridis Date: Tue, 10 May 2022 08:41:03 +0000 (+0000) Subject: added newteams moveup and movedown X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=8fab54b45c49a75c2e924e853ff4f1c12ce36265;p=ihaspeks%2Faptbot-ihaspeks.git added newteams moveup and movedown --- diff --git a/skgyorugo/commands/movedown.py b/skgyorugo/commands/movedown.py new file mode 100644 index 0000000..df3566a --- /dev/null +++ b/skgyorugo/commands/movedown.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +formatter = logging.Formatter("[%(levelname)s] %(asctime)s: %(name)s; %(message)s") + +file_handler = logging.FileHandler("/var/log/aptbot/logs.log") +file_handler.setFormatter(formatter) + +logger.handlers = [] +logger.addHandler(file_handler) + +PERMISSION = 10 +PREFIX = "\\" +DESCRIPTION = r"Move the user down one row in the queue." +USER_COOLDOWN = 0 +GLOBAL_COOLDOWN = 0 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + + +def main(bot: Bot, message: Message): + twitch_name = message.tags.get("reply-parent-user-login", None) + if not twitch_name: + twitch_name = message.value.split(" ")[1] + twitch = ttv_api.users.get_users(user_logins=[twitch_name]) + if not twitch: + bot.send_privmsg( + message.channel, + "There was an issue fetching the user's twitch data. They weren't moved down in the list Sadge", + reply=message.tags["id"], + ) + return + twitch_id = twitch[0].user_id + + conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) + c = conn.cursor() + + try: + c.execute( + """ + UPDATE + lol_queue + SET + position = ( + SELECT + min(position) + FROM + lol_queue + WHERE + position > ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ) + ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) - position + WHERE + position in ( + ( + SELECT + min(position) + FROM + lol_queue + WHERE + position > ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ), + ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ); + """, + (twitch_id,) * 4, + ) + except sqlite3.IntegrityError: + bot.send_privmsg( + message.channel, "Can't move user down further", reply=message.tags["id"] + ) + conn.close() + return + conn.commit() + bot.send_privmsg( + message.channel, "Successfully moved them down.", reply=message.tags["id"] + ) + conn.close() diff --git a/skgyorugo/commands/moveup.py b/skgyorugo/commands/moveup.py new file mode 100644 index 0000000..43c6b39 --- /dev/null +++ b/skgyorugo/commands/moveup.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +formatter = logging.Formatter("[%(levelname)s] %(asctime)s: %(name)s; %(message)s") + +file_handler = logging.FileHandler("/var/log/aptbot/logs.log") +file_handler.setFormatter(formatter) + +logger.handlers = [] +logger.addHandler(file_handler) + +PERMISSION = 10 +PREFIX = "\\" +DESCRIPTION = r"Move the user up one row in the queue." +USER_COOLDOWN = 0 +GLOBAL_COOLDOWN = 0 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + + +def main(bot: Bot, message: Message): + twitch_name = message.tags.get("reply-parent-user-login", None) + if not twitch_name: + twitch_name = message.value.split(" ")[1] + twitch = ttv_api.users.get_users(user_logins=[twitch_name]) + if not twitch: + bot.send_privmsg( + message.channel, + "There was an issue fetching the user's twitch data. They weren't moved up in the list Sadge", + reply=message.tags["id"], + ) + return + twitch_id = twitch[0].user_id + + conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) + c = conn.cursor() + + try: + c.execute( + """ + UPDATE + lol_queue + SET + position = ( + SELECT + max(position) + FROM + lol_queue + WHERE + position < ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ) + ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) - position + WHERE + position in ( + ( + SELECT + max(position) + FROM + lol_queue + WHERE + position < ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ), + ( + SELECT + position + FROM + lol_queue + WHERE + name = ? + ) + ); + """, + (twitch_id,) * 4, + ) + except sqlite3.IntegrityError: + bot.send_privmsg( + message.channel, "Can't move user up further", reply=message.tags["id"] + ) + conn.close() + return + conn.commit() + bot.send_privmsg( + message.channel, "Successfully moved them up.", reply=message.tags["id"] + ) + conn.close() diff --git a/skgyorugo/commands/newteams.py b/skgyorugo/commands/newteams.py new file mode 100644 index 0000000..4b98302 --- /dev/null +++ b/skgyorugo/commands/newteams.py @@ -0,0 +1,88 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 +import random + +logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) + +formatter = logging.Formatter("[%(levelname)s] %(asctime)s: %(name)s; %(message)s") + +file_handler = logging.FileHandler("/var/log/aptbot/logs.log") +file_handler.setFormatter(formatter) + +logger.handlers = [] +logger.addHandler(file_handler) + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"Check who's currently in queue." +USER_COOLDOWN = 30 +GLOBAL_COOLDOWN = 15 + +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() + + c.execute( + """ + SELECT twitch_id FROM lol_queue WHERE available = 1 ORDER BY position ASC; + """ + ) + fetched = c.fetchall() + queue = [x[0] for x in fetched] + twitch = ttv_api.users.get_users(user_ids=queue) + if not twitch: + bot.send_privmsg( + message.channel, + "There was an issue fetching twitch data. Sadge", + reply=message.tags["id"], + ) + conn.close() + return + queue_names = [] + for twitch_id in queue: + for twitch_user in twitch: + if int(twitch_user.user_id) == int(twitch_id): + queue_names.append(twitch_user.display_name) + break + else: + bot.send_privmsg( + message.channel, + f"There was an issue fetching data from the user with id {twitch_id}. They won't be in the list. This is a very weird problem to have occured. Sadge", + reply=message.tags["id"], + ) + c.execute( + """ + SELECT data FROM lol_queue_data WHERE name = 'queuesize'; + """ + ) + fetched = c.fetchone() + try: + queue_size = fetched[0] + except TypeError: + queue_size = 10 + bot.send_privmsg( + message.channel, + f"There was an issue fetching the queue size, default set to {queue_size}", + reply=message.tags["id"], + ) + + queue = queue_names[:queue_size] + random.shuffle(queue) + blue_team = queue[: queue_size // 2] + red_team = queue[queue_size // 2 :] + + bot.send_privmsg( + message.channel, + [f"Blue team is: {blue_team}", f"Red team is: {red_team}"], + reply=message.tags["id"], + ) + + conn.close() diff --git a/skgyorugo/commands/queue.py b/skgyorugo/commands/queue.py index 01422e6..e313af9 100644 --- a/skgyorugo/commands/queue.py +++ b/skgyorugo/commands/queue.py @@ -3,6 +3,7 @@ import os import logging import ttv_api.users import sqlite3 +import tools.smart_privmsg logger = logging.getLogger(__name__) logger.setLevel(logging.DEBUG) @@ -26,15 +27,6 @@ PATH = os.path.join(PATH, "..") def main(bot: Bot, message: Message): - twitch = ttv_api.users.get_users(user_logins=[message.nick]) - if not twitch: - bot.send_privmsg( - message.channel, - "There was an issue fetching your twitch data. You weren't made unavailable.", - reply=message.tags["id"], - ) - return - twitch_id = twitch[0].user_id conn = sqlite3.connect(os.path.join(PATH, "lol_data.db")) c = conn.cursor() @@ -75,15 +67,16 @@ def main(bot: Bot, message: Message): try: queue_size = fetched[0] except TypeError: + queue_size = 5 bot.send_privmsg( message.channel, - "There was an issue fetching the queue size, default set to 5", + f"There was an issue fetching the queue size, default set to {queue_size}", reply=message.tags["id"], ) - queue_size = 5 - bot.send_privmsg( - message.channel, + tools.smart_privmsg.send( + bot, + message, f"These people are to play with {message.channel}: {queue_names[1:queue_size]} | and these people are waiting: {queue_names[queue_size:]}", reply=message.tags["id"], ) diff --git a/skgyorugo/database_manager.py b/skgyorugo/database_manager.py index bef000f..9f6a95c 100644 --- a/skgyorugo/database_manager.py +++ b/skgyorugo/database_manager.py @@ -94,7 +94,7 @@ def create_lol_database(): """ CREATE TABLE IF NOT EXISTS lol_queue ( twitch_id INTEGER NOT NULL, - position INTEGER NOT NULL UNIQUE, + position INTEGER NOT NULL, available INTEGER NOT NULL, last_available INTEGER, time_remaining INTEGER NOT NULL,