async def func(_, __, m: Message) -> bool: text = m.text or m.caption bot_ = (await get_bot_info()).get("bot") username = "******" + bot_.uname if bot_ else "" pattern = comp_regex(f"(?i)^/start({username})?([\s]+)?$") m.matches = (list(pattern.finditer(text)) if text else None) or None return bool( (m.chat and m.chat.type == "private") and m.matches and not m.edit_date )
from .bot_forwards import ban_from_bot_pm # Load from DB SAVED_SETTINGS = get_collection("CONFIGS") # Loggers CHANNEL = userge.getCLogger(__name__) LOGGER = userge.getLogger(__name__) # User Checks BOT_BAN = get_collection("BOT_BAN") BOT_START = get_collection("BOT_START") # Caches _BOT_PM_MEDIA = None _CACHED_INFO = {} # Regex _TG_LINK_REGEX = comp_regex(r"http[s]?://[\w.]+/(?:[c|s]/)?(\w+)/([0-9]+)") # Pyrogram Filter BotAntiFloodFilter = filters.create(lambda _, __, ___: Config.BOT_ANTIFLOOD) class FloodConfig: BANNED_USERS = filters.user() USERS = defaultdict(list) MESSAGES = 3 SECONDS = 6 OWNER = filters.user(list(Config.OWNER_ID)) ALERT = defaultdict(dict) AUTOBAN = 10 if userge.has_bot:
import asyncio from datetime import datetime from re import compile as comp_regex from pyrogram import filters from pyrogram.errors import BadRequest, FloodWait, Forbidden, MediaEmpty from pyrogram.file_id import PHOTO_TYPES, FileId from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup from userge import Config, Message, get_version, userge, versions from userge.core.ext import RawClient from userge.utils import get_file_id, rand_array _ALIVE_REGEX = comp_regex( r"http[s]?://(i\.imgur\.com|telegra\.ph/file|t\.me)/(\w+)(?:\.|/)(gif|jpg|png|jpeg|[0-9]+)(?:/([0-9]+))?" ) _USER_CACHED_MEDIA, _BOT_CACHED_MEDIA = None, None LOGGER = userge.getLogger(__name__) async def _init() -> None: global _USER_CACHED_MEDIA, _BOT_CACHED_MEDIA if Config.ALIVE_MEDIA and Config.ALIVE_MEDIA.lower() != "false": am_type, am_link = await Bot_Alive.check_media_link( Config.ALIVE_MEDIA.strip()) if am_type and am_type == "tg_media": try: if Config.HU_STRING_SESSION: _USER_CACHED_MEDIA = get_file_id(await userge.get_messages(
import os from json.decoder import JSONDecodeError from re import compile as comp_regex from typing import Set import heroku3 from git import Repo from pyrogram import filters from requests import Session from userge import logbot, logging from . import versions GRepo_regex = comp_regex( "http[s]?://github\.com/(?P<owner>[-\w.]+)/(?P<repo>[-\w.]+)(?:\.git)?") _REPO = Repo() _LOG = logging.getLogger(__name__) logbot.reply_last_msg("Setting Configs ...") class Config: """Configs to setup USERGE-X""" API_ID = int(os.environ.get("API_ID")) API_HASH = os.environ.get("API_HASH") WORKERS = int(os.environ.get("WORKERS")) or os.cpu_count() + 4 BOT_TOKEN = os.environ.get("BOT_TOKEN") HU_STRING_SESSION = os.environ.get("HU_STRING_SESSION") OWNER_ID = tuple(
from .. import ALL_CHATS from ..utils.aiohttp_helper import AioHttp as get_response import ujson import youtube_dl from html_telegraph_poster import TelegraphPoster from pyrogram import filters, Client from pyrogram.errors import FloodWait, MessageNotModified from pyrogram.types import (CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, InputMediaAudio, InputMediaPhoto, InputMediaVideo, Message) from wget import download from youtube_dl.utils import DownloadError, ExtractorError, GeoRestrictedError from youtubesearchpython import VideosSearch BASE_YT_URL = "https://www.youtube.com/watch?v=" YOUTUBE_REGEX = comp_regex( r"(?:youtube\.com|youtu\.be)/(?:[\w-]+\?v=|embed/|v/|shorts/)?([\w-]{11})") PATH = "./ytdl/ytsearch.json" DOWN_PATH = "./ytdl/downloads" class YT_Search_X: def __init__(self): if not os.path.exists(PATH): with open(PATH, "w") as f_x: ujson.dump({}, f_x) with open(PATH) as yt_db: self.db = ujson.load(yt_db) def store_(self, rnd_id: str, results: dict): self.db[rnd_id] = results self.save()
# # Author: GitHub.com/code-rgb [TG - @deleteduser420] # # All rights reserved. import os from re import compile as comp_regex from git import Repo from pyrogram import filters from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup from userge import Config, Message, userge from userge.utils import check_owner, humanbytes plugin_regex = comp_regex(r"Path[\s:]{1,5}(userge/plugins/\w+/\w+\.py)") @userge.on_cmd( "cmdinfo", about={ "header": "find plugin and other info for a given command", "description": "you can also provide optional text to search within the plugin", "usage": "{tr}cmdinfo [cmd] | [optional text]", "examples": "{tr}cmdinfo .ars\n" " {tr}cmdinfo .ars | tracemoepy", }, ) async def see_info(message: Message): cmd_str = message.input_str
import os from asyncio import gather from re import compile as comp_regex import ujson from pyrogram.errors import BadRequest, UserIsBot from pyrogram.types import ReplyKeyboardRemove from userge import Config, Message, userge from userge.utils import get_file_id from userge.utils import parse_buttons as pb from .bot_pm import get_bot_info BTN_REGEX = comp_regex( r"\[([^\[]+?)](\[buttonurl:(?:/{0,2})(.+?)(:same)?]|\(buttonurl:(?:/{0,2})(.+?)(:same)?\))" ) PATH = "./userge/xcache/inline_db.json" CHANNEL = userge.getCLogger(__name__) class Inline_DB: def __init__(self): if not os.path.exists(PATH): d = {} ujson.dump(d, open(PATH, "w")) with open(PATH) as r: self.db = ujson.load(r) def save_msg(self, rnd_id: int, msg_content: str, media_valid: bool, media_id: int):