From 86b18593525c6b5de27ab72df33142e0c3c2955a Mon Sep 17 00:00:00 2001 From: Georgios Atheridis Date: Mon, 16 Jan 2023 03:02:44 +0000 Subject: [PATCH] modified commands --- skgyorugo/commands/{info.py => .info.py} | 0 skgyorugo/commands/cannon.py | 112 +++++++++++++++++++++++ skgyorugo/commands/deadge.py | 112 +++++++++++++++++++++++ skgyorugo/commands/emotes.py | 8 +- skgyorugo/commands/{.joke.py => joke.py} | 0 skgyorugo/commands/opgg.py | 75 +++++++++------ skgyorugo/commands/penta.py | 112 +++++++++++++++++++++++ skgyorugo/commands/quadra.py | 112 +++++++++++++++++++++++ skgyorugo/database_manager.py | 50 ++++++++++ skgyorugo/tools/smart_privmsg.py | 6 ++ 10 files changed, 555 insertions(+), 32 deletions(-) rename skgyorugo/commands/{info.py => .info.py} (100%) create mode 100644 skgyorugo/commands/cannon.py create mode 100644 skgyorugo/commands/deadge.py rename skgyorugo/commands/{.joke.py => joke.py} (100%) create mode 100644 skgyorugo/commands/penta.py create mode 100644 skgyorugo/commands/quadra.py diff --git a/skgyorugo/commands/info.py b/skgyorugo/commands/.info.py similarity index 100% rename from skgyorugo/commands/info.py rename to skgyorugo/commands/.info.py diff --git a/skgyorugo/commands/cannon.py b/skgyorugo/commands/cannon.py new file mode 100644 index 0000000..da342b6 --- /dev/null +++ b/skgyorugo/commands/cannon.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 +import tools.smart_privmsg +import random +import shlex + +logger = logging.getLogger(__name__) + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"Sekiro death counter" +USER_COOLDOWN = 10 +GLOBAL_COOLDOWN = 5 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + +def check_queue(bot: Bot, message: Message, table: str): + conn = sqlite3.connect(os.path.join(PATH, "database.db")) + c = conn.cursor() + + c.execute( + f""" + SELECT id, val FROM varvalues WHERE id = 'cannon'; + """ + ) + _, val = c.fetchone() + + if table == "show": + msg = f"Peks is at cannon {val % 1000} of prestige {val // 1000}" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + + conn.close() + return + if table == "remove": + val = val - 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks is at cannon {val % 1000} of prestige {val // 1000}" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + if table == "add": + val = val + 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks is at cannon {val % 1000} of prestige {val // 1000}" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + + +def parse(query): + query = query.split() + try: + if query[0].lower() == "add": + return {"--do": "add"} + if query[0].lower() == "remove": + return {"--do": "remove"} + except: + pass + return {"--game": "show"} + 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("--do", "show"))) diff --git a/skgyorugo/commands/deadge.py b/skgyorugo/commands/deadge.py new file mode 100644 index 0000000..3c16538 --- /dev/null +++ b/skgyorugo/commands/deadge.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 +import tools.smart_privmsg +import random +import shlex + +logger = logging.getLogger(__name__) + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"Sekiro death counter" +USER_COOLDOWN = 10 +GLOBAL_COOLDOWN = 5 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + +def check_queue(bot: Bot, message: Message, table: str): + conn = sqlite3.connect(os.path.join(PATH, "database.db")) + c = conn.cursor() + + c.execute( + f""" + SELECT id, val FROM varvalues WHERE id = 'deadge_sekiro'; + """ + ) + _, val = c.fetchone() + + if table == "show": + msg = f"Peks has currently died {val} times" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + + conn.close() + return + if table == "remove": + val = val - 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'deadge_sekiro'; + """, + (val,) + ) + + msg = f"Peks has currently died {val} times" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + if table == "add": + val = val + 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'deadge_sekiro'; + """, + (val,) + ) + + msg = f"Peks has currently died {val} times" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + + +def parse(query): + query = query.split() + try: + if query[0].lower() == "add": + return {"--do": "add"} + if query[0].lower() == "remove": + return {"--do": "remove"} + except: + pass + return {"--game": "show"} + 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("--do", "show"))) diff --git a/skgyorugo/commands/emotes.py b/skgyorugo/commands/emotes.py index fe6f8f9..d18808f 100644 --- a/skgyorugo/commands/emotes.py +++ b/skgyorugo/commands/emotes.py @@ -2,11 +2,11 @@ from aptbot.bot import Message, Commands, Bot import tools.smart_privmsg import urllib3 -PERMISSION = 99 -PREFIX = "?" +PERMISSION = 9 +PREFIX = "\\" DESCRIPTION = "" -USER_COOLDOWN = 90 -GLOBAL_COOLDOWN = 60 +USER_COOLDOWN = 900 +GLOBAL_COOLDOWN = 600 def main(bot: Bot, message: Message): diff --git a/skgyorugo/commands/.joke.py b/skgyorugo/commands/joke.py similarity index 100% rename from skgyorugo/commands/.joke.py rename to skgyorugo/commands/joke.py diff --git a/skgyorugo/commands/opgg.py b/skgyorugo/commands/opgg.py index 6964cd9..aabf5c2 100644 --- a/skgyorugo/commands/opgg.py +++ b/skgyorugo/commands/opgg.py @@ -6,6 +6,7 @@ from lol_api import spectator_v4 from lol_api import summoner_v4 import ttv_api.users from tools import smart_privmsg +import json logger = logging.getLogger(__name__) @@ -20,6 +21,15 @@ GLOBAL_COOLDOWN = 15 PATH = os.path.dirname(os.path.realpath(__file__)) PATH = os.path.join(PATH, "..") +def find_champion(champ_id: int) -> str: + with open(os.path.join(PATH, "data/champion.json"), "r") as f: + champion_data = json.load(f) + champ_id = str(champ_id) + champion_data = champion_data["data"] + for champion in champion_data: + if champion_data[champion]["key"] == champ_id: + return champion_data[champion]["name"] + return "404" def main(bot: Bot, message: Message): index_skip = 0 @@ -30,19 +40,19 @@ def main(bot: Bot, message: Message): except IndexError: twitch_user = message.tags.get("reply-parent-display-name", message.channel) twitch_id = message.tags.get( - "reply-parent-user-id", - ttv_api.users.get_users(user_logins=[message.channel]), - ) + "reply-parent-user-id", + ttv_api.users.get_users(user_logins=[message.channel]), + ) else: twitch_id = ttv_api.users.get_users(user_logins=[twitch_user]) if not twitch_id: logger.warning( - f"There was an issue getting twitch data for user {twitch_id}; message id was: {message.tags['id']}" - ) + f"There was an issue getting twitch data for user {twitch_id}; message id was: {message.tags['id']}" + ) smart_privmsg.send( - bot, message, "Couldn't retrieve data", reply=message.tags["id"] - ) + bot, message, "Couldn't retrieve data", reply=message.tags["id"] + ) return if not isinstance(twitch_id, str): @@ -54,26 +64,26 @@ def main(bot: Bot, message: Message): c = conn.cursor() c.execute( - """ + """ SELECT summoner_id, puuid FROM accounts WHERE twitch_id = ?; """, (twitch_id,), - ) + ) fetched = c.fetchall() c.execute( - """ + """ SELECT twitch_id, summoner_id FROM accounts; """, - ) + ) fetched_all = c.fetchall() if not fetched: smart_privmsg.send( - bot, - message, - f"No summoners added for {twitch_user}", - reply=message.tags["id"], - ) + bot, + message, + f"No summoners added for {twitch_user}", + reply=message.tags["id"], + ) conn.close() return @@ -87,11 +97,11 @@ def main(bot: Bot, message: Message): break else: smart_privmsg.send( - bot, - message, - f"{twitch_user} is currently not in game. These are all of their summoners: {summoner_names}", - reply=message.tags["id"], - ) + bot, + message, + f"{twitch_user} is currently not in game. These are all of their summoners: {summoner_names}", + reply=message.tags["id"], + ) conn.close() return @@ -99,15 +109,24 @@ def main(bot: Bot, message: Message): for summoner in info.participants: for f in fetched_all: if summoner.summoner_id == f[1] and summoner.summoner_id != fetched[0][0]: - play_with.append(ttv_api.users.get_users(user_ids=[f[0]])[0].display_name), + play_with.append( + { + "name": ttv_api.users.get_users(user_ids=[f[0]])[0].display_name, + "champion": find_champion(summoner.champion_id), + }, + ) break msg = f"{twitch_user} is currently playing a game on: {summoner_names[-1]}" if play_with: - msg += f" and is playing with {play_with}." + msg += " and is playing with" + for player in play_with: + msg += f" {player['name']} on {player['champion']} |" + msg = msg[:-1] + "." + smart_privmsg.send( - bot, - message, - msg, - reply=message.tags["id"], - ) + bot, + message, + msg, + reply=message.tags["id"], + ) conn.close() diff --git a/skgyorugo/commands/penta.py b/skgyorugo/commands/penta.py new file mode 100644 index 0000000..01f4219 --- /dev/null +++ b/skgyorugo/commands/penta.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 +import tools.smart_privmsg +import random +import shlex + +logger = logging.getLogger(__name__) + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"Sekiro death counter" +USER_COOLDOWN = 10 +GLOBAL_COOLDOWN = 5 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + +def check_queue(bot: Bot, message: Message, table: str): + conn = sqlite3.connect(os.path.join(PATH, "database.db")) + c = conn.cursor() + + c.execute( + f""" + SELECT id, val FROM varvalues WHERE id = 'penta'; + """ + ) + _, val = c.fetchone() + + if table == "show": + msg = f"Peks has gotten {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + + conn.close() + return + if table == "remove": + val = val - 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks has gotten {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + if table == "add": + val = val + 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks has gotten {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + + +def parse(query): + query = query.split() + try: + if query[0].lower() == "add": + return {"--do": "add"} + if query[0].lower() == "remove": + return {"--do": "remove"} + except: + pass + return {"--game": "show"} + 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("--do", "show"))) diff --git a/skgyorugo/commands/quadra.py b/skgyorugo/commands/quadra.py new file mode 100644 index 0000000..ede98b1 --- /dev/null +++ b/skgyorugo/commands/quadra.py @@ -0,0 +1,112 @@ +from aptbot.bot import Message, Commands, Bot +import os +import logging +import ttv_api.users +import sqlite3 +import tools.smart_privmsg +import random +import shlex + +logger = logging.getLogger(__name__) + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"Sekiro death counter" +USER_COOLDOWN = 10 +GLOBAL_COOLDOWN = 5 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + +def check_queue(bot: Bot, message: Message, table: str): + conn = sqlite3.connect(os.path.join(PATH, "database.db")) + c = conn.cursor() + + c.execute( + f""" + SELECT id, val FROM varvalues WHERE id = 'quadra'; + """ + ) + _, val = c.fetchone() + + if table == "show": + msg = f"Peks has missed out on {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + + conn.close() + return + if table == "remove": + val = val - 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks has missed out on {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + if table == "add": + val = val + 1 + c.execute( + f""" + UPDATE varvalues SET val = ? WHERE id = 'cannon'; + """, + (val,) + ) + + msg = f"Peks has missed out on {val} pentas!" + + tools.smart_privmsg.send( + bot, + message, + msg, + reply=message.tags["id"], + ) + conn.commit() + conn.close() + return + + +def parse(query): + query = query.split() + try: + if query[0].lower() == "add": + return {"--do": "add"} + if query[0].lower() == "remove": + return {"--do": "remove"} + except: + pass + return {"--game": "show"} + 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("--do", "show"))) diff --git a/skgyorugo/database_manager.py b/skgyorugo/database_manager.py index be6c0e8..ee653c3 100644 --- a/skgyorugo/database_manager.py +++ b/skgyorugo/database_manager.py @@ -109,6 +109,33 @@ def create_lol_database(): ) logger.info(f"created table lol_queue_data") + c.execute( + """ + CREATE TABLE IF NOT EXISTS ow ( + twitch_id INTEGER NOT NULL, + position INTEGER NOT NULL, + available INTEGER NOT NULL, + last_available INTEGER, + time_remaining INTEGER NOT NULL, + team INTEGER, + priority_queue INTEGER, + PRIMARY KEY (twitch_id) + ); + """ + ) + logger.info(f"created table ow") + + c.execute( + """ + CREATE TABLE IF NOT EXISTS ow_data ( + name TEXT NOT NULL, + data INTEGER NOT NULL, + PRIMARY KEY (name) + ); + """ + ) + logger.info(f"created table ow_data") + conn.commit() conn.close() @@ -135,6 +162,29 @@ def create_database(): ) logger.info(f"created table commands") + c.execute( + """ + CREATE TABLE IF NOT EXISTS varvalues ( + id TEXT NOT NULL, + val INTEGER NOT NULL, + PRIMARY KEY (id) + ) + """ + ) + logger.info(f"created table varvalues") + + + c.execute( + """ + CREATE TABLE IF NOT EXISTS clips ( + url TEXT NOT NULL, + from_user INTEGER NOT NULL, + PRIMARY KEY (url) + ) + """ + ) + logger.info(f"created table clips") + c.execute( """ CREATE TABLE IF NOT EXISTS users ( diff --git a/skgyorugo/tools/smart_privmsg.py b/skgyorugo/tools/smart_privmsg.py index 13c477d..eaf01b9 100644 --- a/skgyorugo/tools/smart_privmsg.py +++ b/skgyorugo/tools/smart_privmsg.py @@ -30,6 +30,9 @@ def send_safe(bot: Bot, channel: str, messages: Union[str, list], reply=None): messages[i] = messages[i][1:] else: break + messages[i] = messages[i].replace("always", "alwase") + messages[i] = messages[i].replace("Always", "Alwase") + messages[i] = messages[i].replace("ALWAYS", "ALWASE") else: while True: if ( @@ -41,6 +44,9 @@ def send_safe(bot: Bot, channel: str, messages: Union[str, list], reply=None): messages = messages[1:] else: break + messages = messages.replace("always", "alwase") + messages = messages.replace("Always", "Alwase") + messages = messages.replace("ALWAYS", "ALWASE") bot.send_privmsg(channel, messages, reply) -- 2.30.2