Initial commit v2 (token free)

This commit is contained in:
Xargana 2025-05-07 17:44:50 +03:00
parent 93235081ea
commit 0cd926b9a7
19 changed files with 1458 additions and 0 deletions

1
utils/__init__.py Normal file
View file

@ -0,0 +1 @@
# Empty init to make directory a package

33
utils/storage.py Normal file
View file

@ -0,0 +1,33 @@
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

20
utils/time_parser.py Normal file
View file

@ -0,0 +1,20 @@
import re
time_regex = re.compile(r'(\d+)([smhd])') # Matches 4m2s, 1h30m, etc.
def parse_time(time_str):
"""
Parse time strings like "4m2s", "1h30m" into seconds.
Args:
time_str: String in format like "4m2s", "1h30m"
Returns:
Integer of total seconds or None if invalid
"""
units = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400}
try:
total_seconds = sum(int(amount) * units[unit] for amount, unit in time_regex.findall(time_str))
return total_seconds if total_seconds > 0 else None
except:
return None