From: Georgios Atheridis Date: Sun, 3 Apr 2022 16:24:23 +0000 (+0300) Subject: changed command change permissions to 10, beginning of variable database X-Git-Url: https://git.atheridis.org/?a=commitdiff_plain;h=664ed493148989976755e33a8455c23924b2e533;p=ihaspeks%2Faptbot-ihaspeks.git changed command change permissions to 10, beginning of variable database --- diff --git a/skgyorugo/README.md b/skgyorugo/README.md index b601724..cf5045a 100644 --- a/skgyorugo/README.md +++ b/skgyorugo/README.md @@ -2,7 +2,7 @@ - [x] youtube api - [x] raid / host shoutout -- [ ] latege (command and auto), could look through auto schedule +- [x] latege (command and auto), could look through auto schedule - [ ] basic math polish notation - [x] translator - [ ] (?t a replied message / database in memory of messages) @@ -15,21 +15,22 @@ - [ ] streamer time - [ ] list maker (who's up for flex) - [ ] variable counter with cross-command functionality +- [ ] random variable getter from db {random.quote} - [ ] specific word in message {message.0}, {message.1}, etc. - [ ] replied variable {reply.nick} {reply.message} {reply.message.0} - [ ] sub sellout bot - [ ] schedule ## Basic Commands -- [ ] int -- [ ] bald +- [x] int +- [x] bald - [ ] milk pasta -- [ ] make spam always output max length -- [ ] tea -- [ ] coffee +- [x] make spam always output max length +- [x] tea +- [x] coffee - [ ] smelly - [ ] coin - [ ] permissions - [ ] jam -- [ ] screamlads -- [ ] supporters +- [x] screamlads +- [x] supporters diff --git a/skgyorugo/commands/addcommand.py b/skgyorugo/commands/addcommand.py index 9f91e44..bd6fc1d 100644 --- a/skgyorugo/commands/addcommand.py +++ b/skgyorugo/commands/addcommand.py @@ -2,7 +2,7 @@ from aptbot.bot import Message, Commands, Bot import sqlite3 import os -PERMISSION = 1 +PERMISSION = 10 PREFIX = '\\' DESCRIPTION = "" USER_COOLDOWN = 0 diff --git a/skgyorugo/commands/editcommand.py b/skgyorugo/commands/editcommand.py index ec35331..99973bd 100644 --- a/skgyorugo/commands/editcommand.py +++ b/skgyorugo/commands/editcommand.py @@ -2,7 +2,7 @@ from aptbot.bot import Message, Commands, Bot import sqlite3 import os -PERMISSION = 1 +PERMISSION = 10 PREFIX = '\\' DESCRIPTION = "" USER_COOLDOWN = 0 diff --git a/skgyorugo/commands/emotes.py b/skgyorugo/commands/emotes.py index ed4c7b6..fe28f23 100644 --- a/skgyorugo/commands/emotes.py +++ b/skgyorugo/commands/emotes.py @@ -1,7 +1,6 @@ from aptbot.bot import Message, Commands, Bot import tools.smart_privmsg import urllib3 -import os PERMISSION = 99 PREFIX = '?' @@ -9,27 +8,16 @@ DESCRIPTION = "" USER_COOLDOWN = 90 GLOBAL_COOLDOWN = 60 -OAUTH = os.getenv("APTBOT_OAUTH") -CLIENT_ID = os.getenv("APTBOT_CLIENT_ID") - -HEADER = { - "Authorization": f"Bearer {OAUTH}", - "Client-Id": f"{CLIENT_ID}", - "Content-Type": "application/json", -} - def main(bot: Bot, message: Message): http = urllib3.PoolManager() r1 = http.request( "GET", f"https://twitch.center/customapi/bttvemotes?channel={message.channel}", - headers=HEADER, ) r2 = http.request( "GET", f"https://twitch.center/customapi/ffzemotes?channel={message.channel}", - headers=HEADER, ) if r1.status != 200 or r2.status != 200: diff --git a/skgyorugo/commands/removecommand.py b/skgyorugo/commands/removecommand.py index d41a26d..8e83b26 100644 --- a/skgyorugo/commands/removecommand.py +++ b/skgyorugo/commands/removecommand.py @@ -2,7 +2,7 @@ from aptbot.bot import Message, Commands, Bot import sqlite3 import os -PERMISSION = 1 +PERMISSION = 10 PREFIX = '\\' DESCRIPTION = "" USER_COOLDOWN = 0 diff --git a/skgyorugo/commands/spam.py b/skgyorugo/commands/spam.py index cdb5588..c872036 100644 --- a/skgyorugo/commands/spam.py +++ b/skgyorugo/commands/spam.py @@ -1,5 +1,4 @@ from aptbot.bot import Message, Commands, Bot -import tools.smart_privmsg PERMISSION = 99 PREFIX = '?' @@ -13,6 +12,6 @@ MAX_LENGTH = 469 def main(bot: Bot, message: Message): msg = ' '.join(message.value.split(' ')[1:]) new_msg = "" - while len(new_msg) + len(msg) > MAX_LENGTH: + while len(new_msg) + len(msg) < MAX_LENGTH: new_msg += msg + " " - bot.send_privmsg(message.channel, msg) + bot.send_privmsg(message.channel, new_msg) diff --git a/skgyorugo/database_manager.py b/skgyorugo/database_manager.py index 41b72c7..c291775 100644 --- a/skgyorugo/database_manager.py +++ b/skgyorugo/database_manager.py @@ -4,6 +4,60 @@ import ttv_api.users PATH = os.path.dirname(os.path.realpath(__file__)) +STREAMER_PATH = os.path.abspath(os.path.join(__file__, "..")) +streamer_login = os.path.split(STREAMER_PATH)[1] + + +def create_variables_db(): + conn = sqlite3.connect(os.path.join(PATH, "variables.db")) + c = conn.cursor() + + try: + c.execute( + """ + CREATE TABLE variables ( + name TEXT NOT NULL, + type TEXT NOT NULL, + value TEXT NOT NULL, + PRIMARY KEY (name) + ) + """ + ) + except sqlite3.OperationalError as e: + print(e) + + try: + c.execute( + """ + CREATE TABLE methods ( + name TEXT NOT NULL, + type TEXT NOT NULL, + input TEXT NOT NULL, + PRIMARY KEY (name, type) + ) + """ + ) + except sqlite3.OperationalError as e: + print(e) + + try: + c.execute( + """ + CREATE TABLE list_values ( + id INTEGER NOT NULL, + name TEXT NOT NULL, + type TEXT NOT NULL, + value TEXT NOT NULL, + FOREIGN KEY(name) REFERENCES variables(name) + PRIMARY KEY (id, name) + ) + """ + ) + except sqlite3.OperationalError as e: + print(e) + + conn.close() + def create_database(): conn = sqlite3.connect(os.path.join(PATH, "database.db")) @@ -23,8 +77,8 @@ def create_database(): ) """ ) - except sqlite3.OperationalError: - print("Table commands exists") + except sqlite3.OperationalError as e: + print(e) try: c.execute( @@ -37,12 +91,22 @@ def create_database(): """ ) except sqlite3.OperationalError as e: - print(f"Table users exists: {e}") - else: - admin_id = ttv_api.users.get_users(user_logins=["skgyorugo"]) - if admin_id: + print(e) + + admin_id = ttv_api.users.get_users(user_logins=["skgyorugo"]) + broadcaster_id = ttv_api.users.get_users(user_logins=[streamer_login]) + if admin_id: + try: c.execute("INSERT INTO users VALUES (?, ?)", (admin_id[0].user_id, 0)) + except sqlite3.IntegrityError as e: + print(e) + if broadcaster_id: + try: + c.execute("INSERT INTO users VALUES (?, ?)", + (broadcaster_id[0].user_id, 1)) + except sqlite3.IntegrityError as e: + print(e) try: c.execute( @@ -57,8 +121,8 @@ def create_database(): ) """ ) - except sqlite3.OperationalError: - print("Table cooldowns exists") + except sqlite3.OperationalError as e: + print(e) try: c.execute( @@ -70,8 +134,8 @@ def create_database(): ) """ ) - except sqlite3.OperationalError: - print("Table cooldowns exists") + except sqlite3.OperationalError as e: + print(e) try: c.execute( @@ -85,8 +149,8 @@ def create_database(): ) """ ) - except sqlite3.OperationalError: - print("Table commands exists") + except sqlite3.OperationalError as e: + print(e) try: c.execute( @@ -98,8 +162,8 @@ def create_database(): ) """ ) - except sqlite3.OperationalError: - print("Table cooldowns exists") + except sqlite3.OperationalError as e: + print(e) try: c.execute( @@ -113,7 +177,7 @@ def create_database(): """ ) except sqlite3.OperationalError as e: - print(f"Table users exists: {e}") + print(e) conn.commit() conn.close() diff --git a/skgyorugo/main.py b/skgyorugo/main.py index 0817a1e..12cc36c 100644 --- a/skgyorugo/main.py +++ b/skgyorugo/main.py @@ -89,6 +89,7 @@ for spec in auto_message_specs: database_manager.create_database() +database_manager.create_variables_db() database_manager.update_commands_in_database(commands_modules, commands) database_manager.update_auto_messages_in_database( auto_message_modules, auto_messages) diff --git a/skgyorugo/tools/smart_privmsg.py b/skgyorugo/tools/smart_privmsg.py index 2e25282..e625c12 100644 --- a/skgyorugo/tools/smart_privmsg.py +++ b/skgyorugo/tools/smart_privmsg.py @@ -16,10 +16,15 @@ def _split_message(message: str) -> list[str]: return word_list -def send(bot: Bot, message_data: Message, message: str): - for msg in _split_message(' '.join(message_data.value.split(' ')[1:])): - message = message.replace("{message}", msg) - message = message.replace("{nick}", message_data.nick) - message = message.replace("{channel}", message_data.channel) +def send(bot: Bot, message_data: Message, message: str, to_remove: int = 1): + # for msg in _split_message(' '.join(message_data.value.split(' ')[1:])): + # message = message.replace("{message}", msg) + # message = message.replace("{nick}", message_data.nick) + # message = message.replace("{channel}", message_data.channel) + msg = ' '.join(message_data.value.split(' ')[to_remove:]) + message = message.replace("{message}", msg) + message = message.replace("{nick}", message_data.nick) + message = message.replace("{channel}", message_data.channel) + messages = _split_message(message) bot.send_privmsg(message_data.channel, messages) diff --git a/skgyorugo/variable_manager/parser.py b/skgyorugo/variable_manager/parser.py new file mode 100644 index 0000000..26bacc7 --- /dev/null +++ b/skgyorugo/variable_manager/parser.py @@ -0,0 +1,58 @@ +import os +import re +import sqlite3 + +PATH = os.path.dirname(os.path.realpath(__file__)) +PATH = os.path.join(PATH, "..") + + +class Expression: + def __init__(self, name: str, list_id: str, method: str, value: str): + self.name = name + self.list_id = list_id + self.method = method + self.value = value + + def eval(self): + conn = sqlite3.connect(os.path.join(PATH, "variables.db")) + c = conn.cursor() + + if self.list_id: + # TODO + c.execute( + """ + SELECT + * + FROM + variables + """ + ) + pass + + def __repr__(self) -> str: + return f"Expression('{self.name}', '{self.list_id}', '{self.method}', '{self.value}')" + + +def parse(text: str): + value = text + reg_parse = re.compile(r"^\$(\w+)\[?(\d+)?\]?\.(\w+)\((.+)?\)$") + + expressions: list[Expression] = [] + + while True: + try: + name, list_id, method, value = reg_parse.findall(value)[0] + except IndexError: + break + expressions.append(Expression(name, list_id, method, value)) + print(expressions) + if 2: + return None + return "" + + +if __name__ == "__main__": + # parse(r"$fib[12].set($fib[11].add($fib[10].value()))") + # parse(r"$quotes[2].set(Hello, world)") + # parse(r"") + parse(r"$cannon.set(23)")