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__))
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
)
)
conn.commit()
+ time.sleep(1.5)
conn.close()
message.tags["user-id"]
)
- print(f"user perm is: {user_perm}")
-
c.execute(
"SELECT prefix, command FROM commands WHERE permission >= ? ORDER BY permission ASC",
(
fetched_commands = c.fetchall()
- print(f"fetched commands is: {fetched_commands}")
-
conn.commit()
conn.close()
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)
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,
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()
import analyze_command
import scripts.unit_converter
import database_manager
+import analyze_auto_message
from importlib import reload
reload(tools.raid)
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))
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(
)
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())
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)
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)
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])
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,
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()),
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()),