from userge import Config, Message, get_collection, userge SAVED_SETTINGS = get_collection("CONFIGS") async def _init() -> None: data = await SAVED_SETTINGS.find_one({"_id": "TAG_LOGGING"}) if data: Config.TAG_LOGGING = bool(data["is_active"]) async with aiofiles.open("userge/xcache/get_me.json", "w+") as fn: json_data = str(await userge.get_me()) await fn.write(json_data) tagLoggingFilter = filters.create(lambda _, __, ___: Config.TAG_LOGGING) @userge.on_cmd( "tag_log", about={ "header": "Toggle logging of PM and groups[all]", "description": "Logs all PMs and group mentions", "flag": { "-c": "Check tag_log status", }, "usage": "{tr}tag_log", }, allow_channels=False, ) async def all_log(message: Message):
inline_query.answer(results=results, cache_time=3) @app.on_chosen_inline_result() def chosen(app, inline_query): name = user_dict[inline_query.from_user.id][inline_query.result_id] text = pokemon_text(pk, name, expanded=0) markup = data_markup(name, expanded=0) app.edit_inline_text(inline_message_id=inline_query.inline_message_id, text=text, parse_mode="HTML", reply_markup=markup) @app.on_callback_query( filters.create(lambda _, __, query: "infos" in query.data)) def expand(app, query): expanded = int(re.split("/", query.data)[1]) pkmn = re.split("/", query.data)[2] text = pokemon_text(pk, pkmn, expanded=expanded) markup = data_markup(pkmn, expanded=expanded) app.answer_callback_query(query.id) app.edit_inline_text(inline_message_id=query.inline_message_id, text=text, parse_mode="HTML", reply_markup=markup) @app.on_callback_query( filters.create(lambda _, __, query: "moveset" in query.data)) def moveset(app, query):
@app.on_message(filters.user(SUDOERS) & filters.command("log")) @capture_err async def logs_chat(_, message): keyb = types.InlineKeyboardMarkup([[ types.InlineKeyboardButton("Paste on Nekobin", callback_data="paste_log_nekobin") ]]) await message.reply_document("error.log", reply_markup=keyb) def logs_callback(_, __, query): if re.match("paste_log_nekobin", query.data): return True logs_create = filters.create(logs_callback) @app.on_callback_query(logs_create) async def paste_log_neko(client, query): if query.from_user.id == OWNER_ID or SUDO_USER_ID: j = open("error.log", "r") data = await nekobin.neko(j.read()) keyb = types.InlineKeyboardMarkup( [[types.InlineKeyboardButton("Pasted!", url=f"{data}")]]) await query.message.edit_caption("Successfully Nekofied", reply_markup=keyb) else: await client.answer_callback_query(query.id, "'Blue Button Must Press', huh?", show_alert=True)
from pyrogram import filters from ..screenshotbot import ScreenShotBot from ..utils import display_settings from ..config import Config @ScreenShotBot.on_callback_query( filters.create(lambda _, query: query.data.startswith('set'))) async def settings_cb(c, m): try: _, typ, action = m.data.split('+') # Reverse compatibility. except: _, typ = m.data.split('+') chat_id = m.from_user.id if typ == 'af': as_file = await c.db.is_as_file(chat_id) await c.db.update_as_file(chat_id, not as_file) alert_text = 'Successfully changed screenshot upload mode!' elif typ == 'wm': watermark_text = await c.db.get_watermark_text(chat_id) if watermark_text: await c.db.update_watermark_text(chat_id) alert_text = 'Successfully removed watermark text.' else: alert_text = 'Use /set_watermark to add new watermark text.' elif typ == 'sv': sample_duration = await c.db.get_sample_duration(chat_id)
parse_mode="markdown", reply_to_message_id=message.message_id ) @Client.on_message(filters.private & filters.incoming & filters.command(['help'])) def _help(client, message): client.send_message(chat_id = message.chat.id, text = tr.HELP_MSG[1], parse_mode="markdown", disable_notification = True, reply_markup = InlineKeyboardMarkup(map(1)), reply_to_message_id = message.message_id ) help_callback_filter = filters.create(lambda _, __, query: query.data.startswith('help+')) @Client.on_callback_query(help_callback_filter) def help_answer(client, callback_query): chat_id = callback_query.from_user.id message_id = callback_query.message.message_id msg = int(callback_query.data.split('+')[1]) client.edit_message_text(chat_id=chat_id, message_id=message_id, text=tr.HELP_MSG[msg], reply_markup=InlineKeyboardMarkup(map(msg)) ) def map(pos): if(pos==1): button = [ [InlineKeyboardButton(text = 'Back', callback_data = "help+2")]
instances[currency] = COINS[upper_currency](xpub=xpub) if not manager_data: raise ValueError("At least one valid currency must be provided") manager = APIManager(manager_data) app = Client("tg", bot_token=TOKEN) mongo = pymongo.MongoClient() mongo = mongo["atomic_tip_db"] satoshis_hundred = 0.000001 # misc deposit_select_filter = filters.create(lambda _, __, query: bool(re.match(r"^deposit_", query.data))) deposit_filter = filters.create(lambda _, __, query: bool(re.match(r"^pay_", query.data))) bet_filter = filters.create(lambda _, __, query: bool(re.match(r"^bet_", query.data))) paylink_filter = filters.create(lambda _, __, query: bool(re.match(r"^pl_", query.data))) paylink_pay_filter = filters.create(lambda _, __, query: bool(re.match(r"^plp_", query.data))) pagination_filter = filters.create(lambda _, __, query: bool(re.match(r"^page_", query.data))) class Paginator: items_per_page = 10 def __init__(self, data): self.data = data def get_page(self, page): end = page * self.items_per_page
def dynamic_data_filter(data): async def func(flt, _, query): return flt.data == query.data # "data" kwarg is accessed with "flt.data" above return filters.create(func, data=data)
InlineKeyboardButton(text="Help", url=f"t.me/{BotUsername}?start=help") ]]) await message.reply( "Contact me in PM to get the list of possible commands.", reply_markup=buttons) else: await help_parser(client, message.chat.id, HELP_STRINGS) async def help_button_callback(_, __, query): if re.match(r"help_", query.data): return True @butler.on_callback_query(filters.create(help_button_callback)) async def help_button(_client, query): mod_match = re.match(r"help_module\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) if mod_match: module = mod_match.group(1) text = "This is help for the module **{}**:\n".format(HELP_COMMANDS[module].__MODULE__) \ + HELP_COMMANDS[module].__HELP__ await query.message.edit(text=text, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( text="Back", callback_data="help_back") ]]))
def give_searched_word_buttons(word): '''Returns a list of buttons''' result = search_number_of_results(word) buttons = [] for key, value in result.items(): if value != 0: buttons.append([ InlineKeyboardButton(f'{key} : ({value})', callback_data=key) ]) return buttons @app.on_callback_query( filters.create(func=lambda _, __, callback_query: callback_query.data in [LABEL_NEXT_PAGE, LABEL_PREVIOUS_PAGE])) def go_next_or_previous_page(client, callback_query): #print(callback_query) message_data = callback_query.data text = str(callback_query.message.text).split('\n')[:3] searched_word = text[0].split(' : ')[1] page_title_numbers = re.split(r'از|صفحه', text[1])[1:] current_page = int(fa2en(page_title_numbers[0])) n_all_page = int(fa2en(page_title_numbers[1])) category = text[2].split(' : ')[1] result = search(text=searched_word, category=category)
def replied_to_user(identifire: int): def my_filter(flt, _, message: Message): if message.reply_to_message: return message.reply_to_message.from_user.id == flt.id return filters.create(my_filter, id=identifire)
def forwarded_from_user(username: str): def my_filter(flt, _, message: Message): if message.forward_from: return message.forward_from.username == flt.username return filters.create(my_filter, username=username)
for x in MENTIONED: msg_text = x["text"] if len(msg_text) >= 11: msg_text = "{}...".format(x["text"]) text += "- [{}](https://t.me/c/{}/{}) ({}): {}\n".format( x["user"], x["chat_id"], x["message_id"], x["chat"], msg_text, ) await app.send_message(LOG_CHAT, text) MENTIONED = [] @app.on_message(filters.mentioned & ~filters.bot & filters.create(user_afk), group=11) async def afk_mentioned(_, message): global MENTIONED afk_time, reason = Zect.afk_stuff() afk_since = get_readable_time(time.time() - afk_time) if "-" in str(message.chat.id): cid = str(message.chat.id)[4:] else: cid = str(message.chat.id) if cid in list(AFK_RESTIRECT) and int(AFK_RESTIRECT[cid]) >= int(time.time()): return AFK_RESTIRECT[cid] = int(time.time()) + DELAY_TIME if reason: await message.reply( f"**I'm AFK right now (since {afk_since})\nReason:** __{reason}__"
from nana import AdminSettings from nana import app from nana import BotUsername from nana import COMMAND_PREFIXES from nana import setbot from nana.languages.strings import tld from nana.utils.Pyroutils import ReplyCheck def speedtest_callback(_, __, query): if re.match('speedtest', query.data): return True speedtest_create = filters.create(speedtest_callback) def speed_convert(size): """Hi human, you can't read bytes?""" power = 2**10 zero = 0 units = {0: '', 1: 'Kb/s', 2: 'Mb/s', 3: 'Gb/s', 4: 'Tb/s'} while size > power: size /= power zero += 1 return f'{round(size, 2)} {units[zero]}' @setbot.on_callback_query(speedtest_create) async def speedtestxyz_callback(client, query):
# Client tikTok = Client("Tiktok-bot", api_id=api_id, api_hash=api_hash, bot_token=token) # join check async def join_check(_, __, msg): try: await tikTok.get_chat_member(channel, msg.from_user.id) status = True except UserNotParticipant: await msg.reply_text(f"برای استفاده رایگان از ربات جهت حمایت از ما لطفا اول در چنل ما جوین شوید!\n{channel}") status = False return status verify_filter = filters.create(join_check) # download Tiktok def downloader(video_url): req = requests.get(f"https://www.wirexteam.ga/tiktok/v1?url={video_url}").json() if req["result"] == False: return 404 request = requests.Request(method='GET',url=req["tiktok"]["download"]) prepared_request = request.prepare() session = requests.Session() response = session.send(request=prepared_request) response.raise_for_status() video = f"{random.choice('0123456789')}_TikTok.mp4" with open(os.path.abspath(video), 'wb') as output_file: output_file.write(response.content) return video, req["tiktok"]["music"]["download"], req["tiktok"]["user"]["author"],\
Hey [{}](tg://user?id={}), Just send me the song name you want to download. English: ```/song Alone Alan Walker``` """ owner_help = """ /blacklist user_id /unblacklist user_id /broadcast message to send /eval python code /chatlist get list of all chats """ @app.on_message( filters.create(ignore_blacklisted_users) & filters.command("start")) async def start(client, message): chat_id = message.chat.id user_id = message.from_user["id"] name = message.from_user["first_name"] if message.chat.type == "private": btn = InlineKeyboardMarkup([[ InlineKeyboardButton(text="Support Group", url="https://t.me/GIRLS_AND_BOYS_CHATTING") ]]) else: btn = None await message.reply(start_text.format(name, user_id), reply_markup=btn) add_chat_to_db(str(chat_id))
# 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: async def _init() -> None:
from pytgcalls import GroupCall # Example of pinned message in a chat: ''' Radio stations: 1. https://hls-01-regions.emgsound.ru/11_msk/playlist.m3u8 To start replay to this message with command !start <ID> To stop use !stop command ''' # Commands available only for anonymous admins async def anon_filter(_, __, m: Message): return bool(m.from_user is None and m.sender_chat) anonymous = filters.create(anon_filter) GROUP_CALLS = {} FFMPEG_PROCESSES = {} @Client.on_message(filters.command('radio', prefixes='!')) async def start(client, message: Message): input_filename = f'radio-{message.chat.id}.raw' group_call = GROUP_CALLS.get(message.chat.id) if group_call is None: group_call = GroupCall(client, input_filename, path_to_log_file='') GROUP_CALLS[message.chat.id] = group_call if not message.reply_to_message or len(message.command) < 2:
else: if message.reply_to_message: del_whitelist(message.reply_to_message.from_user.id) else: message.delete() return await message.edit("**PM permission was revoked!**") await asyncio.sleep(3) await message.delete() def pm_button_callback(_, __, query): if re.match("engine_pm", query.data): return True pm_filter = filters.create(pm_button_callback) @setbot.on_callback_query(pm_filter) async def pm_button(client, query): print(query) if not PM_PERMIT: return if query.from_user.id in AdminSettings and not re.match("engine_pm_apr", query.data) and not re.match("engine_pm_blk", query.data): await client.answer_callback_query(query.id, "No, you can't click by yourself", show_alert=False) return if re.match("engine_pm_block", query.data): await app.send_sticker(query.from_user.id, sticker='CAADAgAD1QQAAp7kTAry1JrL3zVXSxYE') await setbot.edit_inline_text(query.from_user.id, "Sorry, No cash.\nAlso you are getting reported to **SpamWatch**, OwO") await app.block_user(query.from_user.id) elif re.match("engine_pm_nope", query.data):
- Repository: [GitHub](https://github.com/callsmusic/tgvc-userbot) - License: AGPL-3.0-or-later""" # - Pyrogram filters async def current_vc_filter(_, __, m: Message): group_call = mp.group_call if not group_call.is_connected: return False chat_id = int("-100" + str(group_call.full_chat.id)) if m.chat.id == chat_id: return True return False current_vc = filters.create(current_vc_filter) # - Pyrogram handlers @Client.on_message(filters.group & ~filters.edited & current_vc & (filters.regex("^(\\/|!)play$") | filters.audio)) async def play_track(client, m: Message): group_call = mp.group_call playlist = mp.playlist # check audio if m.audio: if m.audio.duration > (DURATION_AUTOPLAY_MIN * 60): reply = await m.reply_text(
from userge.utils import mention_html, time_formatter LOG = userge.getLogger(__name__) CHANNEL = userge.getCLogger(__name__) BOT_BAN = get_collection("BOT_BAN") BOT_START = get_collection("BOT_START") SAVED_SETTINGS = get_collection("CONFIGS") async def _init() -> None: data = await SAVED_SETTINGS.find_one({"_id": "BOT_FORWARDS"}) if data: Config.BOT_FORWARDS = bool(data["is_active"]) allowForwardFilter = filters.create(lambda _, __, ___: Config.BOT_FORWARDS) @userge.on_cmd("bot_fwd", about={"header": "enable / disable Bot Forwards"}, allow_channels=False) async def bot_fwd_(message: Message): """ enable / disable Bot Forwards """ if Config.BOT_FORWARDS: Config.BOT_FORWARDS = False await message.edit("`Bot Forwards disabled !`", del_in=3, log=__name__) else: Config.BOT_FORWARDS = True await message.edit("`Bot Forwards enabled !`", del_in=3, log=__name__) await SAVED_SETTINGS.update_one( {"_id": "BOT_FORWARDS"},
reply_to_message_id=ReplyCheck(message), hide_via=True, ) async def addfav_callback(_, __, query): if re.match(r"addfav_", query.data): return True async def remfav_callback(_, __, query): if re.match(r"remfav_", query.data): return True @setbot.on_callback_query(filters.create(addfav_callback)) async def add_favorite(_, query): if query.from_user.id in AdminSettings: match = query.data.split("_")[1] add = sql.add_fav(Owner, match) if add: await query.answer("Added to Favourites", show_alert=True) else: await query.answer( "Anime already Exists in Favourites", show_alert=True ) else: await query.answer( "You are not Allowed to Press this", show_alert=True
from pyrogram import filters as Filters from ..utils import sample_fn from ..screenshotbot import ScreenShotBot @ScreenShotBot.on_callback_query(Filters.create(lambda _, __, query: query.data.startswith('smpl'))) async def _(c, m): c.loop.create_task(sample_fn(c, m))
from main_startup.core.decorators import friday_on_cmd, listen from main_startup.helper_func.basic_helpers import edit_or_reply, get_text from main_startup.helper_func.logger_s import LogIt afk_sanity_check: dict = {} async def is_afk_(f, client, message): af_k_c = await check_afk() if af_k_c: return bool(True) else: return bool(False) is_afk = filters.create(func=is_afk_, name="is_afk_") @friday_on_cmd( ["afk"], propagate_to_next_handler=False, cmd_help={ "help": "Set AFK!", "example": "{ch}afk", }, ) async def set_afk(client, message): engine = message.Engine pablo = await edit_or_reply(message, engine.get_string("PROCESSING")) msge = None msge = get_text(message)
def CBFilter(data): return filters.create( lambda flt, query: flt.data.lower() == query.data.split(' ', 1)[0]. lower() and query.message.from_user.is_self, data=data # "data" kwarg is accessed with "flt.data" above )
# DELAY_DELETE = 60 START_TIME = datetime.utcnow() START_TIME_ISO = START_TIME.replace(microsecond=0).isoformat() TIME_DURATION_UNITS = ( ('week', 60 * 60 * 24 * 7), ('day', 60 * 60 * 24), ('hour', 60 * 60), ('min', 60), ('sec', 1) ) self_or_contact_filter = filters.create( lambda _, __, message: (message.from_user and message.from_user.is_contact) or message.outgoing ) # https://gist.github.com/borgstrom/936ca741e885a1438c374824efb038b3 async def _human_time_duration(seconds): if seconds == 0: return 'inf' parts = [] for unit, div in TIME_DURATION_UNITS: amount, seconds = divmod(int(seconds), div) if amount > 0: parts.append('{} {}{}' .format(amount, unit, "" if amount == 1 else "s"))
from Bot.sql.chat_sql import add_chat_to_db def yt_search(song): videosSearch = VideosSearch(song, limit=1) result = videosSearch.result() if not result: return False else: video_id = result["result"][0]["id"] url = f"https://youtu.be/{video_id}" return url @app.on_message( filters.create(ignore_blacklisted_users) & filters.command("song")) async def song(client, message): chat_id = message.chat.id user_id = message.from_user["id"] add_chat_to_db(str(chat_id)) args = get_arg(message) + " " + "song" if args.startswith(" "): await message.reply("Enter a song name. Check /help") return "" status = await message.reply("Processing...") video_link = yt_search(args) if not video_link: await status.edit("Song not found.") return "" yt = YouTube(video_link) audio = yt.streams.filter(only_audio=True).first()
]]) await message.reply( "**OWNER ONLY**\nContact me in PM", reply_markup=buttons, ) return await help_parser(client, message.chat.id, ("help_str").format(", ".join(COMMAND_PREFIXES))) async def help_button_callback(_, __, query): if re.match(r"help_", query.data): return True help_button_create = filters.create(help_button_callback) @setbot.on_callback_query(help_button_create) async def help_button(_, query): mod_match = re.match(r"help_module\((.+?)\)", query.data) back_match = re.match(r"help_back", query.data) if mod_match: module = mod_match.group(1) text = ("This is help for the plugins **{}**:\n".format( HELP_COMMANDS[module].__MODULE__) + HELP_COMMANDS[module].__HELP__) await query.message.edit( text=text, reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text="Back", callback_data="help_back")
from pyrogram import filters as Filters from bot.utils import ProcessTypes from bot.screenshotbot import ScreenShotBot from bot.processes import ProcessFactory from bot.messages import Messages as ms from bot.config import Config @ScreenShotBot.on_callback_query( Filters.create(lambda _, __, query: query.data.startswith("smpl"))) async def _(c, m): # c.process_pool.new_task(Utilities().sample_fn(c, m)) try: await m.answer() except Exception: pass await m.edit_message_text( ms.ADDED_TO_QUEUE.format( per_user_process_count=Config.MAX_PROCESSES_PER_USER), ) c.process_pool.new_task(( m.from_user.id, ProcessFactory(process_type=ProcessTypes.SAMPLE_VIDEO, client=c, input_message=m), ))
from pyrogram import filters from pyrogram.errors.exceptions.bad_request_400 import ( ChatAdminRequired, PeerIdInvalid, UsernameNotOccupied, UserNotParticipant, ) from pyrogram.types import ChatPermissions, InlineKeyboardButton, InlineKeyboardMarkup from tg_bot import OWNER_ID from tg_bot import pbot from tg_bot.modules.sql import forceSubscribe_sql as sql logging.basicConfig(level=logging.INFO) static_data_filter = filters.create( lambda _, __, query: query.data == "onUnMuteRequest") @pbot.on_callback_query(static_data_filter) def _onUnMuteRequest(client, cb): user_id = cb.from_user.id chat_id = cb.message.chat.id chat_db = sql.fs_settings(chat_id) if chat_db: channel = chat_db.channel chat_member = client.get_chat_member(chat_id, user_id) if chat_member.restricted_by: if chat_member.restricted_by.id == (client.get_me()).id: try: client.get_chat_member(channel, user_id) client.unban_chat_member(chat_id, user_id)
from bot.hf.gfi import ( get_file_id ) from bot.sql.users_sql import ( get_user_id ) from bot.sql.blacklist_sql import ( add_user_to_bl, rem_user_from_bl ) @Client.on_message( filters.chat(AUTH_USERS) & filters.create( lambda flt, client, message: message.reply_to_message and message.reply_to_message.from_user.is_self ) ) async def on_pm_s(client: Client, message: Message): user_id, reply_message_id = get_user_id( message.reply_to_message.message_id ) recvd_text = message.text.html + " " cmnd_message, ban_un_reason = recvd_text.split(" ", 1) cmnd_message = cmnd_message.strip() ban_un_reason = ban_un_reason.strip() if cmnd_message == BAN_COMMAND: add_user_to_bl(user_id, ban_un_reason)