"""موجّه الأوامر: بدون سلاش، يدعم الأوامر البديلة (اضف امر) و (اسم البوت + الامر).""" import config EXACT = {} PREFIX = {} def exact(*names): def deco(f): for n in names: EXACT[norm(n)] = f return f return deco def prefix(*names): def deco(f): for n in names: PREFIX[norm(n)] = f return f return deco def norm(t): t = (t or "").strip() for a, b in (("أ", "ا"), ("إ", "ا"), ("آ", "ا"), ("ة", "ه"), ("ى", "ي")): t = t.replace(a, b) return t def _match_once(orig, t, chat_id): if chat_id is not None: from core.store import settings alias = settings.get(chat_id, "aliases", {}).get(t) if alias: orig, t = alias, norm(alias) if t in EXACT: return EXACT[t], "" for p in sorted(PREFIX, key=len, reverse=True): if t.startswith(p + " "): return PREFIX[p], orig[len(p):].strip() return None, "" def find(text, chat_id=None): """بيرجع (الدالة, البرميتر) أو (None, '') لو مفيش أمر مطابق.""" orig = (text or "").strip() t = norm(orig) f, arg = _match_once(orig, t, chat_id) if f: return f, arg # إذا لم يطابق مباشرة، جرب إزالة (اسم البوت + مسافة) في البداية from core.store import settings bname = norm(settings.get("global", "bot_name", "") or config.BOT_NAME) if bname and t.startswith(bname + " "): rest = orig[len(bname):].strip() return _match_once(rest, norm(rest), chat_id) return None, "" def is_command(text, chat_id=None): f, _ = find(text, chat_id) return f is not None