Пример #1
0
def banchecker(user_id):
    try:
        casurl = "https://api.cas.chat/check?user_id={}".format(user_id)
        data = get(casurl).json()
    except Exception as e:
        LOGS.info(e)
        data = None
    return bool(data and data["ok"])
Пример #2
0
def extract_w_h(file):
    """ Get width and height of media """
    command_to_run = [
        "ffprobe",
        "-v",
        "quiet",
        "-print_format",
        "json",
        "-show_format",
        "-show_streams",
        file,
    ]
    # https://stackoverflow.com/a/11236144/4723940
    try:
        t_response = subprocess.check_output(command_to_run,
                                             stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as exc:
        LOGS.warning(exc)
    else:
        x_reponse = t_response.decode("UTF-8")
        response_json = json.loads(x_reponse)
        width = int(response_json["streams"][0]["width"])
        height = int(response_json["streams"][0]["height"])
        return width, height
Пример #3
0
async def uploadir(udir_event):
    if udir_event.fwd_from:
        return
    """ For .uploadir command, allows you to upload everything from a folder in the server"""
    input_str = udir_event.pattern_match.group(1)
    if os.path.exists(input_str):
        await udir_event.edit("Downloading Using Userbot Server....")
        lst_of_files = []
        for r, d, f in os.walk(input_str):
            for file in f:
                lst_of_files.append(os.path.join(r, file))
            for file in d:
                lst_of_files.append(os.path.join(r, file))
        LOGS.info(lst_of_files)
        uploaded = 0
        await udir_event.edit(
            "Found {} files. Uploading will start soon. Please wait!".format(
                len(lst_of_files)))
        for single_file in lst_of_files:
            if os.path.exists(single_file):
                # https://stackoverflow.com/a/678242/4723940
                caption_rts = os.path.basename(single_file)
                c_time = time.time()
                if not caption_rts.lower().endswith(".mp4"):
                    await udir_event.client.send_file(
                        udir_event.chat_id,
                        single_file,
                        caption=caption_rts,
                        force_document=False,
                        allow_cache=False,
                        reply_to=udir_event.message.id,
                        progress_callback=lambda d, t: asyncio.get_event_loop(
                        ).create_task(
                            progress(
                                d,
                                t,
                                udir_event,
                                c_time,
                                "Uploading in Progress.......",
                                single_file,
                            )),
                    )
                else:
                    thumb_image = os.path.join(input_str, "thumb.jpg")
                    c_time = time.time()
                    metadata = extractMetadata(createParser(single_file))
                    duration = 0
                    width = 0
                    height = 0
                    if metadata.has("duration"):
                        duration = metadata.get("duration").seconds
                    if metadata.has("width"):
                        width = metadata.get("width")
                    if metadata.has("height"):
                        height = metadata.get("height")
                    await udir_event.client.send_file(
                        udir_event.chat_id,
                        single_file,
                        caption=caption_rts,
                        thumb=thumb_image,
                        force_document=False,
                        allow_cache=False,
                        reply_to=udir_event.message.id,
                        attributes=[
                            DocumentAttributeVideo(
                                duration=duration,
                                w=width,
                                h=height,
                                round_message=False,
                                supports_streaming=True,
                            )
                        ],
                        progress_callback=lambda d, t: asyncio.get_event_loop(
                        ).create_task(
                            progress(d, t, udir_event, c_time, "Uploading...",
                                     single_file)),
                    )
                os.remove(single_file)
                uploaded = uploaded + 1
        await udir_event.edit(
            "Uploaded {} files successfully !!".format(uploaded))
    else:
        await udir_event.edit("404: Directory Not Found")
Пример #4
0
 async def anti_spambot(event):
     if not event.user_joined and not event.user_added:
         return
     chat = event.chat_id
     user = await event.get_user()
     catadmin = await is_admin(bot, chat, bot.uid)
     if not catadmin:
         return
     catbanned = None
     adder = None
     ignore = None
     if event.user_added:
         try:
             adder = event.action_message.sender_id
         except AttributeError:
             return
     async for admin in event.client.iter_participants(
             event.chat_id, filter=ChannelParticipantsAdmins):
         if admin.id == adder:
             ignore = True
             break
     if ignore:
         return
     if is_gbanned(user.id):
         catgban = get_gbanuser(user.id)
         if catgban.reason:
             hmm = await event.reply(
                 f"[{user.first_name}](tg://user?id={user.id}) was gbanned by you for the reason `{catgban.reason}`"
             )
         else:
             hmm = await event.reply(
                 f"[{user.first_name}](tg://user?id={user.id}) was gbanned by you"
             )
         try:
             await bot.edit_permissions(chat, user.id, view_messages=False)
             catbanned = True
         except Exception as e:
             LOGS.info(e)
     if spamwatch and not catbanned:
         ban = spamwatch.get_ban(user.id)
         if ban:
             hmm = await event.reply(
                 f"[{user.first_name}](tg://user?id={user.id}) was banned by spamwatch for the reason `{ban.reason}`"
             )
             try:
                 await bot.edit_permissions(chat,
                                            user.id,
                                            view_messages=False)
                 catbanned = True
             except Exception as e:
                 LOGS.info(e)
     if not catbanned:
         try:
             casurl = "https://api.cas.chat/check?user_id={}".format(
                 user.id)
             data = get(casurl).json()
         except Exception as e:
             LOGS.info(e)
             data = None
         if data and data["ok"]:
             reason = (
                 f"[Banned by Combot Anti Spam](https://cas.chat/query?u={user.id})"
             )
             hmm = await event.reply(
                 f"[{user.first_name}](tg://user?id={user.id}) was banned by Combat anti-spam service(CAS) for the reason check {reason}"
             )
             try:
                 await bot.edit_permissions(chat,
                                            user.id,
                                            view_messages=False)
                 catbanned = True
             except Exception as e:
                 LOGS.info(e)
     if BOTLOG and catbanned:
         await event.client.send_message(
             BOTLOG_CHATID,
             "#ANTISPAMBOT\n"
             f"**User :** [{user.first_name}](tg://user?id={user.id})\n"
             f"**Chat :** {event.chat.title} (`{event.chat_id}`)\n"
             f"**Reason :** {hmm.text}",
         )