Download modules/services.py from ABO3MR/df: direct link, hf CLI and curl.
- Browser
- Download file 14.3 kB
-
https://huggingface.co/spaces/ABO3MR/df/resolve/main/modules/services.py
- Command line
-
hf download hf://spaces/ABO3MR/df/modules/services.py
-
curl -L -o services.py https://huggingface.co/spaces/ABO3MR/df/resolve/main/modules/services.py
14.3 kB
| """الخدمات: ايدي، معلوماتي، المجموعه، المطور، السورس، عدادات، الساعه، احسب.""" | |
| import random, ast, operator | |
| from datetime import datetime | |
| from telegram import InlineKeyboardButton, InlineKeyboardMarkup | |
| from telegram.ext import CallbackQueryHandler | |
| from core.router import exact, prefix, norm | |
| from core import ranks as R | |
| from core import content | |
| from core.store import settings, stats, bump, get_counter, clear_counter, total_msgs, activity_label | |
| from modules.toggles import tg_on | |
| from strings_ar import S | |
| import config | |
| def _user_id_text(update, ctx, t, rank, msgs, pts, dl, edits, bio): | |
| tpl = settings.get(update.effective_chat.id, "id_tpl", "") | |
| if tpl: | |
| out = tpl | |
| for k, v in { | |
| "{الاسم}": t.full_name, "{الايدي}": str(t.id), | |
| "{المعرف}": ("@" + t.username) if t.username else "لا يوجد", | |
| "{الرتبه}": rank, "{الرسائل}": str(msgs), "{التفاعل}": activity_label(msgs), | |
| "{البايو}": bio, "{النقاط}": str(pts), "{السحكات}": str(dl), "{التعديلات}": str(edits), | |
| }.items(): | |
| out = out.replace(k, v) | |
| return out | |
| vals = {"id": t.id, "user": ("@" + t.username) if t.username else "-", | |
| "rank": rank, "msgs": msgs, "pts": pts, "edits": edits, | |
| "act": activity_label(msgs), "bio": bio} | |
| vals["del"] = dl | |
| return S["id_fmt"].format(**vals) | |
| async def my_id(update, ctx, arg=""): | |
| chat = update.effective_chat.id | |
| if not tg_on(chat, "id"): | |
| await update.message.reply_text(S["feature_off"]) | |
| return | |
| m = update.message | |
| t = m.reply_to_message.from_user if m.reply_to_message else update.effective_user | |
| rank = R.get_rank(chat, t.id) | |
| if t.id == config.OWNER_ID and t.id: | |
| rank = "Dev" | |
| msgs = get_counter(chat, t.id, "msgs") | |
| pts = get_counter(chat, t.id, "pts") | |
| dl = get_counter(chat, t.id, "del") | |
| edits = get_counter(chat, t.id, "edits") | |
| try: | |
| c = await ctx.bot.get_chat(t.id) | |
| bio = c.bio or "لا يوجد" | |
| except Exception: | |
| bio = "لا يوجد" | |
| text = _user_id_text(update, ctx, t, rank, msgs, pts, dl, edits, bio) | |
| likes = settings.get(chat, "likes", {}).get(str(t.id), 0) | |
| kb = InlineKeyboardMarkup([[InlineKeyboardButton(f"👍 {likes}", callback_data=f"like:{t.id}", style="primary")]]) | |
| if tg_on(chat, "idphoto"): | |
| try: | |
| ph = await ctx.bot.get_user_profile_photos(t.id, limit=1) | |
| if ph.total_count: | |
| await m.reply_photo(ph.photos[0][-1].file_id, | |
| caption=S["id_caption"] + "\n" + text, reply_markup=kb) | |
| return | |
| except Exception: | |
| pass | |
| await m.reply_text(text, reply_markup=kb) | |
| async def like_cb(update, ctx): | |
| q = update.callback_query | |
| uid = q.data.split(":")[1] | |
| chat = q.message.chat.id | |
| d = settings.get(chat, "likes", {}) | |
| d[uid] = d.get(uid, 0) + 1 | |
| settings.set(chat, "likes", d) | |
| await q.answer("❤️") | |
| try: | |
| await q.edit_message_reply_markup(InlineKeyboardMarkup( | |
| [[InlineKeyboardButton(f"👍 {d[uid]}", callback_data=f"like:{uid}", style="primary")]])) | |
| except Exception: | |
| pass | |
| async def set_id_tpl(update, ctx, arg): | |
| if await R.effective_level(update) < R.level("مدير"): | |
| await update.message.reply_text(S["need_rank"]) | |
| return | |
| m = update.message | |
| tpl = arg | |
| if not tpl and m.reply_to_message: | |
| tpl = m.reply_to_message.text or "" | |
| if not tpl: | |
| await update.message.reply_text( | |
| "✧︙اكتب: تعيين الايدي + الشكل اللي عايزه\n✧︙الدوال المتاحة:\n" | |
| "{الاسم} {الايدي} {المعرف} {الرتبه} {الرسائل} {التفاعل} {البايو} {النقاط} {السحكات} {التعديلات}") | |
| return | |
| settings.set(update.effective_chat.id, "id_tpl", tpl) | |
| await update.message.reply_text(S["done"]) | |
| async def set_id_tpl2(update, ctx, arg=""): | |
| await set_id_tpl(update, ctx, "") | |
| async def del_id_tpl(update, ctx, arg=""): | |
| if await R.effective_level(update) < R.level("مدير"): | |
| await update.message.reply_text(S["need_rank"]) | |
| return | |
| settings.set(update.effective_chat.id, "id_tpl", "") | |
| await update.message.reply_text(S["done"]) | |
| async def me(update, ctx, arg=""): | |
| u = update.effective_user | |
| chat = update.effective_chat.id | |
| n = get_counter(chat, u.id, "msgs") | |
| rank = R.get_rank(chat, u.id) | |
| if u.id == config.OWNER_ID and u.id: | |
| rank = "Dev" | |
| await update.message.reply_text(S["me_fmt"].format(name=u.full_name, id=u.id, rank=rank, | |
| msgs=n, pts=get_counter(chat, u.id, "pts"))) | |
| async def bio(update, ctx, arg=""): | |
| t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user | |
| try: | |
| c = await ctx.bot.get_chat(t.id) | |
| await update.message.reply_text(S["bio_fmt"].format(bio=c.bio or "لا يوجد")) | |
| except Exception: | |
| await update.message.reply_text(S["bio_none"]) | |
| async def avatar(update, ctx, arg=""): | |
| t = update.message.reply_to_message.from_user if update.message.reply_to_message else update.effective_user | |
| ph = await ctx.bot.get_user_profile_photos(t.id, limit=1) | |
| if ph.total_count: | |
| await update.message.reply_photo(ph.photos[0][-1].file_id) | |
| async def group_info(update, ctx, arg=""): | |
| chat = update.effective_chat | |
| admins = 0 | |
| try: | |
| admins = len(await chat.get_administrators()) | |
| except Exception: | |
| pass | |
| try: | |
| members = await chat.get_member_count() | |
| except Exception: | |
| members = 0 | |
| await update.message.reply_text(S["group_info"].format( | |
| name=chat.title or "", admins=admins, members=members, | |
| msgs=total_msgs(chat.id), id=chat.id)) | |
| async def settings_info(update, ctx, arg=""): | |
| chat = update.effective_chat.id | |
| onoff = lambda b: "شغالة ✅" if b else "مقفولة ❌" | |
| await update.message.reply_text(S["settings_info"].format( | |
| welcome=onoff(settings.get(chat, "welcome_on", True) and tg_on(chat, "welcome")), | |
| games=onoff(tg_on(chat, "games")), | |
| replies=onoff(tg_on(chat, "replies")), | |
| night=onoff(tg_on(chat, "night")), | |
| force=settings.get(chat, "force_ch", "") or "مش مفعل")) | |
| async def dev(update, ctx, arg=""): | |
| custom_dev = settings.get("global", "dev_tpl", "") | |
| if custom_dev: | |
| await update.message.reply_text(custom_dev) | |
| return | |
| if not (config.DEV_NAME or config.DEV_USER): | |
| await update.message.reply_text(S["dev_none"]) | |
| return | |
| btns = [] | |
| if config.DEV_USER: | |
| btns.append([InlineKeyboardButton(config.DEV_NAME or "@" + config.DEV_USER, | |
| url=f"https://t.me/{config.DEV_USER}")]) | |
| await update.message.reply_text(S["dev_info"].format( | |
| name=config.DEV_NAME or "-", user=("@" + config.DEV_USER) if config.DEV_USER else "-", | |
| id=config.OWNER_ID or "-"), reply_markup=InlineKeyboardMarkup(btns) if btns else None) | |
| async def source(update, ctx, arg=""): | |
| btns = [] | |
| if config.DEV_USER: | |
| btns.append([InlineKeyboardButton("• المطور •", url=f"https://t.me/{config.DEV_USER}", style="primary")]) | |
| me = await ctx.bot.get_me() | |
| btns.append([InlineKeyboardButton("➕ اضفني لمجموعتك", url=f"https://t.me/{me.username}?startgroup=true")]) | |
| await update.message.reply_text(S["source_info"].format(bot=config.BOT_NAME), | |
| reply_markup=InlineKeyboardMarkup(btns)) | |
| async def top(update, ctx, arg=""): | |
| d = stats.get(update.effective_chat.id, "msgs", {}) | |
| if not d: | |
| await update.message.reply_text(S["top_empty"]) | |
| return | |
| best = sorted(d.items(), key=lambda x: -x[1])[:10] | |
| lines = [S["top_title"]] | |
| for i, (u, n) in enumerate(best, 1): | |
| try: | |
| m = await update.effective_chat.get_member(int(u)) | |
| nm = m.user.first_name | |
| except Exception: | |
| nm = u | |
| lines.append(f"{i}. {nm} — {n}") | |
| await update.message.reply_text("\n".join(lines)) | |
| def _mk_counter(field, fmt): | |
| async def h(update, ctx, arg=""): | |
| n = get_counter(update.effective_chat.id, update.effective_user.id, field) | |
| await update.message.reply_text(S[fmt].format(n=n)) | |
| return h | |
| def _mk_clear(field): | |
| async def h(update, ctx, arg=""): | |
| clear_counter(update.effective_chat.id, update.effective_user.id, field) | |
| await update.message.reply_text(S["counter_cleared"]) | |
| return h | |
| exact("رسائلي", "رسايلي")(_mk_counter("msgs", "msgs_fmt")) | |
| exact("سحكاتي")(_mk_counter("del", "del_fmt")) | |
| exact("تعديلاتي")(_mk_counter("edits", "edits_fmt")) | |
| exact("مسح رسائلي")(_mk_clear("msgs")) | |
| exact("مسح سحكاتي")(_mk_clear("del")) | |
| exact("مسح تعديلاتي")(_mk_clear("edits")) | |
| async def clock(update, ctx, arg=""): | |
| await update.message.reply_text("✧︙الساعه الآن: " + datetime.now().strftime("%I:%M %p")) | |
| async def date(update, ctx, arg=""): | |
| await update.message.reply_text("✧︙تاريخ النهارده: " + datetime.now().strftime("%Y/%m/%d")) | |
| _OPS = {ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, | |
| ast.Div: operator.truediv, ast.Mod: operator.mod, ast.Pow: operator.pow, | |
| ast.USub: operator.neg, ast.UAdd: operator.pos} | |
| def _safe_eval(node): | |
| if isinstance(node, ast.Expression): | |
| return _safe_eval(node.body) | |
| if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)): | |
| return node.value | |
| if isinstance(node, ast.BinOp) and type(node.op) in _OPS: | |
| return _OPS[type(node.op)](_safe_eval(node.left), _safe_eval(node.right)) | |
| if isinstance(node, ast.UnaryOp) and type(node.op) in _OPS: | |
| return _OPS[type(node.op)](_safe_eval(node.operand)) | |
| raise ValueError("bad") | |
| async def calc(update, ctx, arg): | |
| try: | |
| r = _safe_eval(ast.parse(arg, mode="eval")) | |
| await update.message.reply_text(S["calc_result"].format(r=round(r, 6) if isinstance(r, float) else r)) | |
| except Exception: | |
| await update.message.reply_text(S["calc_bad"]) | |
| # ---------- استفتاء وتصويت (استفتاء تليجرام أصلي) ---------- | |
| async def secret_poll(update, ctx, arg): | |
| """استفتاء سري: نفس استفتاء بس التصويت مجهول.""" | |
| parts = [p.strip() for p in (arg or "").split("|")] | |
| q = parts[0] if parts else "" | |
| opts = [p for p in parts[1:] if p][:10] | |
| if "؟" in q: | |
| head, _, tail = q.partition("؟") | |
| if tail.strip(): | |
| q = head.strip() + "؟" | |
| opts = [tail.strip()] + opts | |
| if not q or len(opts) < 2: | |
| await update.message.reply_text(S["poll_usage"]) | |
| return | |
| await update.message.reply_poll(question=q[:300], options=[o[:100] for o in opts], | |
| is_anonymous=True) | |
| async def poll(update, ctx, arg): | |
| """الصيغة: استفتاء السؤال؟ خيار1|خيار2|خيار3""" | |
| parts = [p.strip() for p in (arg or "").split("|")] | |
| q = parts[0] if parts else "" | |
| opts = [p for p in parts[1:] if p][:10] | |
| # لو السؤال وأول خيار متلزقين قبل أول | (مثال: نلعب كورة؟ اه) افصلهم عند علامة الاستفهام | |
| if "؟" in q: | |
| head, _, tail = q.partition("؟") | |
| if tail.strip(): | |
| q = head.strip() + "؟" | |
| opts = [tail.strip()] + opts | |
| if not q or len(opts) < 2: | |
| await update.message.reply_text(S["poll_usage"]) | |
| return | |
| await update.message.reply_poll(question=q[:300], options=[o[:100] for o in opts], | |
| is_anonymous=False) | |
| async def vote(update, ctx, arg): | |
| """تصويت سريع نعم/لا: تصويت السؤال؟""" | |
| q = arg or (update.message.reply_to_message.text if update.message.reply_to_message else "") | |
| if not q: | |
| await update.message.reply_text(S["poll_usage"]) | |
| return | |
| await update.message.reply_poll(question=q[:300], options=["نعم ✅", "لا ❌"], | |
| is_anonymous=False) | |
| async def reverse_text(update, ctx, arg): | |
| """اعكس + نص ← يكتبه بالمقلوب (هزار).""" | |
| text = arg or (update.message.reply_to_message.text if update.message.reply_to_message else "") | |
| if not text: | |
| await update.message.reply_text("✧︙اكتب: اعكس + النص (أو رد على رسالة)") | |
| return | |
| await update.message.reply_text(text[::-1]) | |
| async def mention(update, ctx, arg=""): | |
| t = update.message.reply_to_message.from_user if update.message.reply_to_message else None | |
| if not t: | |
| await update.message.reply_text(S["need_reply"]) | |
| return | |
| await update.message.reply_text("✧︙" + t.mention_html(), parse_mode="HTML") | |
| async def count_msg(update, ctx): | |
| if update.effective_chat.type == "private" or not update.effective_user: | |
| return | |
| bump(update.effective_chat.id, update.effective_user.id, "msgs") | |
| async def count_edit(update, ctx): | |
| if update.effective_chat and update.effective_chat.type != "private" and update.effective_user: | |
| bump(update.effective_chat.id, update.effective_user.id, "edits") | |
| HANDLERS = [CallbackQueryHandler(like_cb, pattern=r"^like:")] | |