From: Georgios Atheridis Date: Mon, 16 Jan 2023 03:02:44 +0000 (+0000) Subject: modified commands X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=1c5f2e3ef1c8f6aa5ee759f5e37e52f2bd9c1415;p=ihaspeks%2Faptbot-ihaspeks.git modified commands --- diff --git a/skgyorugo/commands/.info.py b/skgyorugo/commands/.info.py new file mode 100644 index 0000000..516d02d --- /dev/null +++ b/skgyorugo/commands/.info.py @@ -0,0 +1,18 @@ +from aptbot.bot import Message, Commands, Bot +import tools.smart_start_stream_time + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = "" +USER_COOLDOWN = 5 +GLOBAL_COOLDOWN = 2 + + +def main(bot: Bot, message: Message): + start_stream_ts = tools.smart_start_stream_time.start_stream_timestamp() + if not start_stream_ts: + msg = r"The Sponsor is World of Warships, which is a historical strategy online combat PC game. It looks very 5Head but i will conquer elmoFire so imma be testing it out. If u want to join in with us, try it urself, or if you just want to help me out Gladge u can sign up with my link: https://strms.net/warships_ihaspeks you get a fair few bonuses for using mah link too ihaspeBased and after u have won your first game and bought ur first ship ill get a notification on stream peksJAM" + else: + msg = r"Peks is live so he can awnser that KEKW but here is the link just in case BASED https://strms.net/warships_ihaspeks" + tools.smart_privmsg.send_safe(bot, message.channel, msg) + diff --git a/skgyorugo/commands/.joke.py b/skgyorugo/commands/.joke.py deleted file mode 100644 index c01c1b2..0000000 --- a/skgyorugo/commands/.joke.py +++ /dev/null @@ -1,28 +0,0 @@ -from aptbot.bot import Message, Commands, Bot -import tools.smart_privmsg -import urllib3 -import json - -PERMISSION = 99 -PREFIX = "?" -DESCRIPTION = r"" -USER_COOLDOWN = 30 -GLOBAL_COOLDOWN = 30 - -header = { - "Accept": "application/json", - "User-Agent": "For my twitch bot [MurphyAI] on https://twitch.tv/ihaspeks", -} - - -def main(bot: Bot, message: Message): - http = urllib3.PoolManager() - r = http.request("GET", "https://icanhazdadjoke.com", headers=header) - if r.status != 200: - tools.smart_privmsg.send( - bot, message, f"Couldn't get a joke Sadge", reply=message.tags["id"] - ) - return - - data = json.loads(r.data.decode("utf-8")) - tools.smart_privmsg.send(bot, message, f"{data['joke']}", reply=message.tags["id"]) 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/info.py b/skgyorugo/commands/info.py deleted file mode 100644 index 516d02d..0000000 --- a/skgyorugo/commands/info.py +++ /dev/null @@ -1,18 +0,0 @@ -from aptbot.bot import Message, Commands, Bot -import tools.smart_start_stream_time - -PERMISSION = 99 -PREFIX = "?" -DESCRIPTION = "" -USER_COOLDOWN = 5 -GLOBAL_COOLDOWN = 2 - - -def main(bot: Bot, message: Message): - start_stream_ts = tools.smart_start_stream_time.start_stream_timestamp() - if not start_stream_ts: - msg = r"The Sponsor is World of Warships, which is a historical strategy online combat PC game. It looks very 5Head but i will conquer elmoFire so imma be testing it out. If u want to join in with us, try it urself, or if you just want to help me out Gladge u can sign up with my link: https://strms.net/warships_ihaspeks you get a fair few bonuses for using mah link too ihaspeBased and after u have won your first game and bought ur first ship ill get a notification on stream peksJAM" - else: - msg = r"Peks is live so he can awnser that KEKW but here is the link just in case BASED https://strms.net/warships_ihaspeks" - tools.smart_privmsg.send_safe(bot, message.channel, msg) - diff --git a/skgyorugo/commands/joke.py b/skgyorugo/commands/joke.py new file mode 100644 index 0000000..c01c1b2 --- /dev/null +++ b/skgyorugo/commands/joke.py @@ -0,0 +1,28 @@ +from aptbot.bot import Message, Commands, Bot +import tools.smart_privmsg +import urllib3 +import json + +PERMISSION = 99 +PREFIX = "?" +DESCRIPTION = r"" +USER_COOLDOWN = 30 +GLOBAL_COOLDOWN = 30 + +header = { + "Accept": "application/json", + "User-Agent": "For my twitch bot [MurphyAI] on https://twitch.tv/ihaspeks", +} + + +def main(bot: Bot, message: Message): + http = urllib3.PoolManager() + r = http.request("GET", "https://icanhazdadjoke.com", headers=header) + if r.status != 200: + tools.smart_privmsg.send( + bot, message, f"Couldn't get a joke Sadge", reply=message.tags["id"] + ) + return + + data = json.loads(r.data.decode("utf-8")) + tools.smart_privmsg.send(bot, message, f"{data['joke']}", reply=message.tags["id"]) 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 92bfe14..1b0ff78 100644 --- a/skgyorugo/tools/smart_privmsg.py +++ b/skgyorugo/tools/smart_privmsg.py @@ -32,6 +32,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 ( @@ -43,6 +46,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)