33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import os
|
|
import json
|
|
from config import COMMANDS_DIR, TRACKED_CHANNELS_FILE
|
|
import importlib.util
|
|
|
|
def load_tracked_channels():
|
|
"""Load tracked channel IDs from file"""
|
|
if os.path.exists(TRACKED_CHANNELS_FILE):
|
|
with open(TRACKED_CHANNELS_FILE, 'r') as f:
|
|
return json.load(f)
|
|
return []
|
|
|
|
def save_tracked_channels(tracked_channels):
|
|
"""Save tracked channel IDs to file"""
|
|
with open(TRACKED_CHANNELS_FILE, 'w') as f:
|
|
json.dump(tracked_channels, f)
|
|
|
|
def load_commands():
|
|
"""Load user-defined commands from the commands directory"""
|
|
os.makedirs(COMMANDS_DIR, exist_ok=True)
|
|
commands = {}
|
|
for filename in os.listdir(COMMANDS_DIR):
|
|
if filename.endswith(".py"):
|
|
cmd_name = filename[:-3]
|
|
cmd_path = os.path.join(COMMANDS_DIR, filename)
|
|
|
|
spec = importlib.util.spec_from_file_location(cmd_name, cmd_path)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
|
|
if hasattr(module, "run") and callable(module.run):
|
|
commands[cmd_name] = module.run
|
|
return commands |