fixed bugs and made spam to spam as much as possible
authorGeorgios Atheridis <atheridis@tutamail.com>
Sat, 2 Apr 2022 04:01:56 +0000 (07:01 +0300)
committerGeorgios Atheridis <atheridis@tutamail.com>
Sat, 2 Apr 2022 04:01:56 +0000 (07:01 +0300)
skgyorugo/analyze_auto_message.py
skgyorugo/commands/commands.py
skgyorugo/commands/spam.py
skgyorugo/database_manager.py
skgyorugo/main.py
skgyorugo/tools/smart_privmsg.py
skgyorugo/tools/smart_start_stream_time.py

index 5031b03ba1405c1e91ca2b1e12e13848ffb0d743..44a596858f185e7bd53abdd9222e89b6fdb6630a 100644 (file)
@@ -3,7 +3,11 @@ import os
 import sqlite3
 import time
 import tools.smart_privmsg
-from tools.smart_start_stream_time import start_stream_timestamp as stream_ts
+import tools.smart_start_stream_time
+from importlib import reload
+
+reload(tools.smart_privmsg)
+reload(tools.smart_start_stream_time)
 
 PATH = os.path.dirname(os.path.realpath(__file__))
 
@@ -12,7 +16,7 @@ def do_auto_message(bot: Bot, message: Message, auto_message_modules: dict):
     conn = sqlite3.connect(os.path.join(PATH, "database.db"))
     c = conn.cursor()
 
-    start_stream_ts = stream_ts()
+    start_stream_ts = tools.smart_start_stream_time.start_stream_timestamp()
     if not start_stream_ts:
         return
 
@@ -54,4 +58,5 @@ def do_auto_message(bot: Bot, message: Message, auto_message_modules: dict):
             )
         )
         conn.commit()
+        time.sleep(1.5)
     conn.close()
index c6788588f4d0e3da6e9b202975e426a2bb973a1c..d2cf437b1bd3bcff5eba864e0f0a35c18a4ee823 100644 (file)
@@ -23,8 +23,6 @@ def main(bot: Bot, message: Message):
         message.tags["user-id"]
     )
 
-    print(f"user perm is: {user_perm}")
-
     c.execute(
         "SELECT prefix, command FROM commands WHERE permission >= ? ORDER BY permission ASC",
         (
@@ -34,8 +32,6 @@ def main(bot: Bot, message: Message):
 
     fetched_commands = c.fetchall()
 
-    print(f"fetched commands is: {fetched_commands}")
-
     conn.commit()
     conn.close()
 
index 13c8d20582fdcc0b871eb943202eca35c3d79023..cdb558885bcbb868255a337f7a6e3ddf66ec85d8 100644 (file)
@@ -7,9 +7,12 @@ DESCRIPTION = ""
 USER_COOLDOWN = 10
 GLOBAL_COOLDOWN = 0
 
+MAX_LENGTH = 469
+
 
 def main(bot: Bot, message: Message):
     msg = ' '.join(message.value.split(' ')[1:])
-    msg = (msg + ' ') * 10
-    tools.smart_privmsg.send(bot, message, msg)
-    # bot.send_privmsg(message.channel, msg)
+    new_msg = ""
+    while len(new_msg) + len(msg) > MAX_LENGTH:
+        new_msg += msg + " "
+    bot.send_privmsg(message.channel, msg)
index 98dbae99e1dc62087d112e4dba6aa77171852149..41b72c70c94aa0c456b96588e7aa3be66994d0ac 100644 (file)
@@ -104,7 +104,7 @@ def create_database():
     try:
         c.execute(
             """
-            CREATE TABLE streamer_info (
+            CREATE TABLE stream_info (
                 start_stream_ts INTEGER NOT NULL,
                 last_checked INTEGER NOT NULL,
                 ended INTEGER NOT NULL,
@@ -156,14 +156,31 @@ def update_auto_messages_in_database(modules, auto_messages):
         auto_message_cooldown = modules[auto_message_name].COOLDOWN
         auto_message_end_time = modules[auto_message_name].END_TIME
         auto_message_last_used = 0
-        c.execute(
-            "REPLACE INTO commands VALUES (?, ?, ?, ?)",
-            (
-                auto_message_name,
-                auto_message_cooldown,
-                auto_message_end_time,
-                auto_message_last_used,
+        try:
+            c.execute(
+                "INSERT INTO auto_messages (name, cooldown, end_time, last_used) VALUES (?, ?, ?, ?)",
+                (
+                    auto_message_name,
+                    auto_message_cooldown,
+                    auto_message_end_time,
+                    auto_message_last_used,
+                )
+            )
+        except Exception as e:
+            c.execute(
+                """
+                UPDATE auto_messages
+                SET
+                    cooldown = ?,
+                    end_time = ?
+                WHERE
+                    name = ?
+                """,
+                (
+                    auto_message_cooldown,
+                    auto_message_end_time,
+                    auto_message_name,
+                )
             )
-        )
     conn.commit()
     conn.close()
index 0908c85a844dd8eca5626bf9eca04225490ea0df..0817a1e4a64020fbf249e7d5b2ab36dbc8bfc1db 100644 (file)
@@ -9,6 +9,7 @@ import tools.permissions
 import analyze_command
 import scripts.unit_converter
 import database_manager
+import analyze_auto_message
 from importlib import reload
 
 reload(tools.raid)
@@ -17,14 +18,18 @@ reload(tools.permissions)
 reload(analyze_command)
 reload(scripts.unit_converter)
 reload(database_manager)
+reload(analyze_auto_message)
 
 
 PATH = os.path.dirname(os.path.realpath(__file__))
 COMMANDS_PATH = os.path.join(PATH, "commands")
 AUTO_MESSAGES_PATH = os.path.join(PATH, "auto_messages")
 
-specs = {}
-modules = {}
+commands_specs = {}
+commands_modules = {}
+
+auto_message_specs = {}
+auto_message_modules = {}
 
 commands = [
     c for c in os.listdir(COMMANDS_PATH) if os.path.isfile(os.path.join(COMMANDS_PATH, c))
@@ -33,15 +38,16 @@ commands = filter(lambda x: not x.startswith('.'), commands)
 commands = filter(lambda x: os.path.splitext(x)[1] == ".py", commands)
 commands = list(commands)
 for command in commands:
-    specs[command.split('.')[0]] = (
+    commands_specs[command.split('.')[0]] = (
         importlib.util.spec_from_file_location(
             f"{command.split('.')[0]}",
             os.path.join(COMMANDS_PATH, command)
         )
     )
+print(f"my commands are {commands}")
 
 auto_messages = [
-    c for c in os.listdir(COMMANDS_PATH) if os.path.isfile(os.path.join(COMMANDS_PATH, c))
+    c for c in os.listdir(AUTO_MESSAGES_PATH) if os.path.isfile(os.path.join(AUTO_MESSAGES_PATH, c))
 ]
 auto_messages = filter(lambda x: not x.startswith('.'), auto_messages)
 auto_messages = filter(
@@ -50,19 +56,32 @@ auto_messages = filter(
 )
 auto_messages = list(auto_messages)
 for auto_message in auto_messages:
-    specs[auto_message.split('.')[0]] = (
+    auto_message_specs[auto_message.split('.')[0]] = (
         importlib.util.spec_from_file_location(
             f"{auto_message.split('.')[0]}",
-            os.path.join(COMMANDS_PATH, auto_message)
+            os.path.join(AUTO_MESSAGES_PATH, auto_message)
         )
     )
 
-for spec in specs:
-    modules[spec] = importlib.util.module_from_spec(specs[spec])
-    if not specs[spec]:
+for spec in commands_specs:
+    commands_modules[spec] = importlib.util.module_from_spec(
+        commands_specs[spec])
+    if not commands_specs[spec]:
+        continue
+    try:
+        commands_specs[spec].loader.exec_module(commands_modules[spec])
+    except Exception as e:
+        print()
+        print(traceback.format_exc())
+        print(f"Problem Loading Module: {e}")
+
+for spec in auto_message_specs:
+    auto_message_modules[spec] = importlib.util.module_from_spec(
+        auto_message_specs[spec])
+    if not auto_message_specs[spec]:
         continue
     try:
-        specs[spec].loader.exec_module(modules[spec])
+        auto_message_specs[spec].loader.exec_module(auto_message_modules[spec])
     except Exception as e:
         print()
         print(traceback.format_exc())
@@ -70,12 +89,16 @@ for spec in specs:
 
 
 database_manager.create_database()
-database_manager.update_commands_in_database(modules, commands)
+database_manager.update_commands_in_database(commands_modules, commands)
+database_manager.update_auto_messages_in_database(
+    auto_message_modules, auto_messages)
 
 
 def main(bot: Bot, message: Message):
     if message.command == Commands.PRIVMSG:
-        analyze_command.do_command(bot, message, modules)
+        analyze_command.do_command(bot, message, commands_modules)
         scripts.unit_converter.send_metric(bot, message)
 
+    analyze_auto_message.do_auto_message(bot, message, auto_message_modules)
+
     tools.raid.raid(bot, message)
index f2276a6b03a55c731a0ab432a207a0a666a828f6..2e25282a3f63e94b4217f25d1d98abe27c0c01cc 100644 (file)
@@ -17,8 +17,6 @@ def _split_message(message: str) -> list[str]:
 
 
 def send(bot: Bot, message_data: Message, message: str):
-    # msg = ' '.join(message_data.value.split(' ')[1:])
-    # msg = split_message(msg)
     for msg in _split_message(' '.join(message_data.value.split(' ')[1:])):
         message = message.replace("{message}", msg)
         message = message.replace("{nick}", message_data.nick)
index 52189367fd18bf4e939bfbdc7d74fe4d2ea92f19..27aaca42a83ef4be7d3b7118b665ec1fd6126621 100644 (file)
@@ -21,24 +21,34 @@ def start_stream_timestamp() -> Optional[int]:
     conn = sqlite3.connect(os.path.join(PATH, "database.db"))
     c = conn.cursor()
 
-    c.execute(
-        """
-        SELECT
-            start_stream_ts,
-            last_checked,
-            ended
-        FROM
-            stream_info
-        WHERE
-            last_checked = (SELECT MAX(last_checked) FROM stream_info);
-            AND ended = 0
-        """
-    )
+    c.execute("SELECT MAX(last_checked) FROM stream_info")
+    max_last_checked = c.fetchone()
+    if max_last_checked:
+        c.execute(
+            """
+            SELECT
+                start_stream_ts,
+                last_checked,
+                ended
+            FROM
+                stream_info
+            WHERE
+                last_checked = ?
+                AND ended = 0
+            """,
+            (
+                max_last_checked[0],
+            )
+        )
+        print(f"I checked {max_last_checked}")
 
     fetched = c.fetchone()
     if fetched:
         start_stream_ts, last_checked, _ = fetched
-        if last_checked + CHECK_STREAMTIME_CD < time.time():
+        print(f"stream ts = {start_stream_ts}")
+        print(
+            f"last_checked {last_checked} + check_streamtime_cd {CHECK_STREAMTIME_CD} \n time.time {time.time()}")
+        if time.time() < last_checked + CHECK_STREAMTIME_CD:
             return start_stream_ts
 
     stream_info = ttv_api.stream.get_streams(user_logins=[streamer_login])
@@ -47,12 +57,12 @@ def start_stream_timestamp() -> Optional[int]:
 
     if not stream_info:
         start_stream_ts, last_checked, _ = fetched
-        if last_checked + MAX_OFF_STREAM_MARGIN < time.time():
+        if time.time() < last_checked + MAX_OFF_STREAM_MARGIN:
             conn.close()
             return
 
         c.execute(
-            "REPLACE INTO commands VALUES (?, ?, ?)",
+            "REPLACE INTO stream_info VALUES (?, ?, ?)",
             (
                 start_stream_ts,
                 last_checked,
@@ -65,8 +75,9 @@ def start_stream_timestamp() -> Optional[int]:
 
     if not fetched:
         start_stream_ts = int(stream_info[0].started_at.timestamp())
+        print("TEST")
         c.execute(
-            "REPLACE INTO commands VALUES (?, ?, ?)",
+            "REPLACE INTO stream_info VALUES (?, ?, ?)",
             (
                 start_stream_ts,
                 int(time.time()),
@@ -77,9 +88,10 @@ def start_stream_timestamp() -> Optional[int]:
         conn.close()
         return start_stream_ts
 
+    print("MORE TEST")
     start_stream_ts, last_checked, _ = fetched
     c.execute(
-        "REPLACE INTO commands VALUES (?, ?, ?)",
+        "REPLACE INTO stream_info VALUES (?, ?, ?)",
         (
             start_stream_ts,
             int(time.time()),