コード例 #1
0
ファイル: locks.py プロジェクト: tz-ash/CatUserbot
async def _(event):
    if not event.is_private:
        chat = await event.get_chat()
        admin = chat.admin_rights
        creator = chat.creator
        if not admin and not creator:
            return
    # check for "lock" "bots"
    if not is_locked(event.chat_id, "bots"):
        return
    # bots are limited Telegram accounts,
    # and cannot join by themselves
    if event.user_added:
        users_added_by = event.action_message.sender_id
        is_ban_able = False
        rights = types.ChatBannedRights(until_date=None, view_messages=True)
        added_users = event.action_message.action.users
        for user_id in added_users:
            user_obj = await event.client.get_entity(user_id)
            if user_obj.bot:
                is_ban_able = True
                try:
                    await event.client(
                        functions.channels.EditBannedRequest(
                            event.chat_id, user_obj, rights))
                except Exception as e:
                    await event.reply(
                        "I don't seem to have ADMIN permission here. \n`{}`".
                        format(str(e)))
                    update_lock(event.chat_id, "bots", False)
                    break
        if BOTLOG and is_ban_able:
            ban_reason_msg = await event.reply(
                "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat."
                .format(users_added_by))
コード例 #2
0
ファイル: locks_IQ.py プロジェクト: d3s44/IQTHON
async def _(event):
    # # @IQTHON AND DAV @KLANR C
    # # @IQTHON AND DAV @KLANR C
    if is_locked(event.chat_id, "بوتات"):
        # bots are limited Telegram accounts,
        # and cannot join by themselves
        if event.user_added:
            users_added_by = event.action_message.from_id
            is_ban_able = False
            rights = types.ChatBannedRights(
                until_date=None,
                view_messages=True
            )
            added_users = event.action_message.action.users
            for user_id in added_users:
                user_obj = await borg.get_entity(user_id)
                if user_obj.bot:
                    is_ban_able = True
                    try:
                        await borg(functions.channels.EditBannedRequest(
                            event.chat_id,
                            user_obj,
                            rights
                        ))
                    except Exception as e:
                        await event.reply(
                            "ليس لدي اذن ادمن هنا. \n`{}`".format(str(e))
                        )
                        update_lock(event.chat_id, "بوتات", False)
                        break
            if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
                ban_reason_msg = await event.reply(
                    "!البوتات [user](tg://user?id={}) الرجاء عدم اضافه بوتات هنا.".format(users_added_by)
                )
コード例 #3
0
async def _(event):
    # TODO: exempt admins from locks
    # check for "lock" "bots"
    if is_locked(event.chat_id, "bots"):
        # bots are limited Telegram accounts,
        # and cannot join by themselves
        if event.user_added:
            users_added_by = event.action_message.from_id
            is_ban_able = False
            rights = types.ChatBannedRights(until_date=None,
                                            view_messages=True)
            added_users = event.action_message.action.users
            for user_id in added_users:
                user_obj = await borg.get_entity(user_id)
                if user_obj.bot:
                    is_ban_able = True
                    try:
                        await borg(
                            functions.channels.EditBannedRequest(
                                event.chat_id, user_obj, rights))
                    except Exception as e:
                        await event.reply(
                            "Burada ADMIN iznim yok gibi görünüyor. \n`{}`".
                            format(str(e)))
                        update_lock(event.chat_id, "bots", False)
                        break
            if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
                ban_reason_msg = await event.reply(
                    "! UYARI [kullanıcı] (tg: // user? id = {}) Lütfen bu sohbete BOT Eklemeyin."
                    .format(users_added_by))
コード例 #4
0
ファイル: locks.py プロジェクト: perman-dev/perman_ub
async def _(event):
    # TODO: exempt admins from locks
    # check for "lock" "bots"
    if is_locked(event.chat_id, "bots"):
        # bots are limited Telegram accounts,
        # and cannot join by themselves
        if event.user_added:
            users_added_by = event.action_message.sender_id
            is_ban_able = False
            rights = types.ChatBannedRights(until_date=None, view_messages=True)
            added_users = event.action_message.action.users
            for user_id in added_users:
                user_obj = await borg.get_entity(user_id)
                if user_obj.bot:
                    is_ban_able = True
                    try:
                        await borg(
                            functions.channels.EditBannedRequest(
                                event.chat_id, user_obj, rights
                            )
                        )
                    except Exception as e:
                        await event.reply(
                            "I don't seem to have ADMIN permission here. \n`{}`".format(
                                str(e)
                            )
                        )
                        update_lock(event.chat_id, "bots", False)
                        break
            if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
                ban_reason_msg = await event.reply(
                    "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(
                        users_added_by
                    )
                )
コード例 #5
0
async def _(event):
    if event.fwd_from:
        return
    input_str = event.pattern_match.group(1)
    peer_id = event.chat_id
    msg = None
    media = None
    sticker = None
    gif = None
    gamee = None
    ainline = None
    gpoll = None
    adduser = None
    cpin = None
    changeinfo = None
    if "msg" in input_str:
        msg = True
    if "media" in input_str:
        media = True
    if "sticker" in input_str:
        sticker = True
    if "gif" in input_str:
        gif = True
    if "gamee" in input_str:
        gamee = True
    if "ainline" in input_str:
        ainline = True
    if "gpoll" in input_str:
        gpoll = True
    if "adduser" in input_str:
        adduser = True
    if "cpin" in input_str:
        cpin = True
    if "changeinfo" in input_str:
        changeinfo = True
    banned_rights = types.ChatBannedRights(
        until_date=None,
        # view_messages=None,
        send_messages=msg,
        send_media=media,
        send_stickers=sticker,
        send_gifs=gif,
        send_games=gamee,
        send_inline=ainline,
        send_polls=gpoll,
        invite_users=adduser,
        pin_messages=cpin,
        change_info=changeinfo,
    )
    try:
        result = await borg(
            functions.messages.EditChatDefaultBannedRightsRequest(
                peer=peer_id, banned_rights=banned_rights))
        # logger.info(result.stringify())
    except Exception as e:
        await event.edit(str(e))
    else:
        await asyncio.sleep(5)
        await event.delete()
コード例 #6
0
async def _(event):
    try:
        from sql_helpers.locks_sql import update_lock, is_locked
    except Exception as e:
        logger.info("DB_URI is not configured.")
        logger.info(str(e))
        return False
    if await is_admin(event.client, event.chat_id, event.action_message.from_id):
        return
    if is_locked(event.chat_id, "bots"):
        # bots are limited Telegram accounts,
        # and cannot join by themselves
        if event.user_added:
            users_added_by = event.action_message.from_id
            is_ban_able = False
            rights = types.ChatBannedRights(
                until_date=None,
                view_messages=True
            )
            added_users = event.action_message.action.users
            for user_id in added_users:
                user_obj = await event.client.get_entity(user_id)
                if user_obj.bot:
                    is_ban_able = True
                    try:
                        await event.client(functions.channels.EditBannedRequest(
                            event.chat_id,
                            user_obj,
                            rights
                        ))
                    except Exception as e:
                        await event.reply(
                            "I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
                        )
                        update_lock(event.chat_id, "bots", False)
                        break
            if Config.G_BAN_LOGGER_GROUP is not None and is_ban_able:
                ban_reason_msg = await event.reply(
                    "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
                )
コード例 #7
0
async def _(event):
    # result = await borg(functions.channels.GetParticipantRequest(
    #     channel=event.chat_id,
    #     user_id=event.action_message.from_id
    # ))
    # if not event.is_private and not isinstance(result.participant, (types.ChannelParticipantCreator, types.ChannelParticipantAdmin)):
    #     # locks should not be affected for admins of the group
    #     return False
    # check for "lock" "bots"
    if is_locked(event.chat_id, "bots"):
        # bots are limited Telegram accounts,
        # and cannot join by themselves
        if event.user_added:
            users_added_by = event.action_message.from_id
            is_ban_able = False
            rights = types.ChatBannedRights(
                until_date=None,
                view_messages=True
            )
            added_users = event.action_message.action.users
            for user_id in added_users:
                user_obj = await borg.get_entity(user_id)
                if user_obj.bot:
                    is_ban_able = True
                    try:
                        await borg(functions.channels.EditBannedRequest(
                            event.chat_id,
                            user_obj,
                            rights
                        ))
                    except Exception as e:
                        await event.reply(
                            "I don't seem to have ADMIN permission here. \n`{}`".format(str(e))
                        )
                        update_lock(event.chat_id, "bots", False)
                        break
            if Config.G_BAN_LOGGER_GROUP != -100123456789 and is_ban_able:
                ban_reason_msg = await event.reply(
                    "!warn [user](tg://user?id={}) Please Do Not Add BOTs to this chat.".format(users_added_by)
                )
コード例 #8
0
ファイル: locks.py プロジェクト: ImAnmusics1/BotHub-
async def _(event):
     # Space weirdness in regex required because argument is optional and other
     # commands start with ".lock"
    if event.fwd_from:
        return
    input_str = event.pattern_match.group("target")
    peer_id = event.chat_id
    if input_str in (("bots", "commands", "email", "forward", "url")):
        try:
            from sql_helpers.locks_sql import update_lock
        except Exception as e:
            logger.info("DB_URI is not configured.")
            logger.info(str(e))
            return False
        update_lock(peer_id, input_str, True)
        await event.edit(
            "Locked {}".format(input_str)
        )
    else:
        msg = None
        media = None
        sticker = None
        gif = None
        gamee = None
        ainline = None
        gpoll = None
        adduser = None
        cpin = None
        changeinfo = None
        if input_str:
            if "msg" in input_str:
                msg = True
            if "media" in input_str:
                media = True
            if "sticker" in input_str:
                sticker = True
            if "gif" in input_str:
                gif = True
            if "gamee" in input_str:
                gamee = True
            if "ainline" in input_str:
                ainline = True
            if "gpoll" in input_str:
                gpoll = True
            if "adduser" in input_str:
                adduser = True
            if "cpin" in input_str:
                cpin = True
            if "changeinfo" in input_str:
                changeinfo = True
        banned_rights = types.ChatBannedRights(
            until_date=None,
            # view_messages=None,
            send_messages=msg,
            send_media=media,
            send_stickers=sticker,
            send_gifs=gif,
            send_games=gamee,
            send_inline=ainline,
            send_polls=gpoll,
            invite_users=adduser,
            pin_messages=cpin,
            change_info=changeinfo,
        )
        try:
            result = await event.client(
                functions.messages.EditChatDefaultBannedRightsRequest(
                    peer=peer_id,
                    banned_rights=banned_rights
                )
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await event.edit(str(e))
        else:
            await event.edit(
                "Current Chat Default Permissions Changed Successfully, in API"
            )
コード例 #9
0
ファイル: locks_IQ.py プロジェクト: d3s44/IQTHON
async def _(event):
     # @IQTHON AND DAV @KLANR C
     # commands start with ".lock"
    if event.fwd_from:
        return
    input_str = event.pattern_match.group("target")
    peer_id = event.chat_id
    if input_str in (("بوتات", "تعليق", "ايميل", "توجيه", "رابط")):
        update_lock(peer_id, input_str, True)
        await event.edit(
            "Locked {}".format(input_str)
        )
    else:
        msg = None
        media = None
        sticker = None
        gif = None
        gamee = None
        ainline = None
        gpoll = None
        adduser = None
        cpin = None
        changeinfo = None
        if input_str:
            if "قفل الرسائل" in input_str:
                msg = True
            if "الوسائط" in input_str:
                media = True
            if "الملصقات" in input_str:
                sticker = True
            if "المتحركات" in input_str:
                gif = True
            if "الالعاب" in input_str:
                gamee = True
            if "الانلاين" in input_str:
                ainline = True
            if "gpoll" in input_str:
                gpoll = True
            if "الاضافه" in input_str:
                adduser = True
            if "التثبيت" in input_str:
                cpin = True
            if "المعلومات" in input_str:
                changeinfo = True
        banned_rights = types.ChatBannedRights(
            until_date=None,
            # view_messages=None,
            send_messages=msg,
            send_media=media,
            send_stickers=sticker,
            send_gifs=gif,
            send_games=gamee,
            send_inline=ainline,
            send_polls=gpoll,
            invite_users=adduser,
            pin_messages=cpin,
            change_info=changeinfo,
        )
        try:
            result = await borg(  # @IQTHON AND DAV @KLANR C
                functions.messages.EditChatDefaultBannedRightsRequest(
                    peer=peer_id,
                    banned_rights=banned_rights
                )
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await event.edit(str(e))
        else:
            await event.edit(
                "تم القفل من صلاحيات المجموعه بنجاح"
            )
コード例 #10
0
ファイル: event.py プロジェクト: yphkwhoami/tg_userapi_bot
async def handler(event):
    #print('---incoming--- ' + str(event.chat_id) )
    #listen for whitelisted user id (single user chat)
    #to check if this is received from this user in single chat
    manage_group_id = 0
    for conf in config:
        #get group id from matched whitelist table
        #allow one user for one group only
        if event.chat_id == conf[0]:
            manage_group_id = conf[1]
            break

    listener_client = event.client
    if event.is_reply and manage_group_id > 0:
        locked = False
        if is_locked(event.from_id):
            if debug_mode == True:
                print(str(event.from_id) + 'LOCKED!')
            await event.reply(
                'Another process is running, please try again later.')
            locked = True
    #handling reply , for banning user when using cdrom report
        omessage = await event.get_reply_message()
        message_info = await this_user_info(omessage.id, False
                                            )  #check if it is single message
        #get the user info to be banned from the reply message
        if locked == False:
            Path(tg_config.setting['session_path'] +
                 str(event.from_id)).touch()
            if message_info:
                #ignore if he reply to his own sent message ..
                if event.chat_id != omessage.from_id:
                    #print('this is reply from '+ str(omessage.id))
                    #print('--------------')
                    #ban user here , need grant me permission!
                    #listener_client = TelegramClient(tg_config.setting['session']['runtime'] + '_' + str(manage_group_id), api_id, api_hash)
                    try:
                        #await listener_client.start()
                        this_channel = await listener_client.get_input_entity(
                            PeerChannel(message_info[2]))
                        this_user = await listener_client.get_input_entity(
                            PeerUser(message_info[0]))
                        result = await listener_client(
                            functions.channels.EditBannedRequest(
                                channel=this_channel,
                                user_id=this_user,
                                banned_rights=types.ChatBannedRights(
                                    until_date=datetime(future_year, 6, 25),
                                    view_messages=True,
                                    send_messages=True,
                                    send_media=True,
                                    send_stickers=True,
                                    send_gifs=True,
                                    send_games=True,
                                )))
                    except Exception as e:
                        if debug_mode == True:
                            await event.reply('Error : ' + str(e))
                            print(str(e))
                        else:
                            await event.reply(
                                'Error : please make sure user bot have permission to do so'
                            )
                        #await listener_client.disconnect()
                    else:
                        await omessage.edit('[Banned] ' + omessage.text)
                        await listener_client(
                            functions.messages.DeleteMessagesRequest(
                                id=[event.id], revoke=True))
                        #await listener_client.disconnect()
            else:
                #no single message detected, try check if it is batch message
                message_infos = await this_user_info(omessage.id, True)
                if len(message_infos) > 0:
                    #listener_client = TelegramClient(tg_config.setting['session']['runtime'] + '_' + str(manage_group_id), api_id, api_hash)
                    if event.text.lower() == 'all':
                        #ban all users of this replied message
                        baned_num = 0
                        ban_ids = []
                        #await listener_client.start()
                        for mi in message_infos:
                            #ban_ids.append(mi[0])
                            #perform ban action
                            try:
                                #await listener_client.start()
                                this_channel = await listener_client.get_input_entity(
                                    PeerChannel(manage_group_id))
                                this_user = await listener_client.get_input_entity(
                                    PeerUser(mi[0]))
                                result = await listener_client(
                                    functions.channels.EditBannedRequest(
                                        channel=this_channel,
                                        user_id=this_user,
                                        banned_rights=types.ChatBannedRights(
                                            until_date=datetime(
                                                future_year, 6, 25),
                                            view_messages=True,
                                            send_messages=True,
                                            send_media=True,
                                            send_stickers=True,
                                            send_gifs=True,
                                            send_games=True,
                                        )))
                            except Exception as e:
                                if debug_mode == True:
                                    await event.reply('Error : ' + str(e))
                                    print(str(e))
                                else:
                                    await event.reply(
                                        'Error : please make sure user bot have permission to do so'
                                    )
                            else:
                                baned_num += 1

                        #await listener_client.disconnect()
                        await event.reply('Banned ' + str(baned_num) +
                                          ' users')
                        #await event.reply('Banned '+str(', '.join(ban_ids)))
                    else:
                        try:
                            valid_ids = []
                            ban_ids = []
                            is_failed = False
                            for mi in message_infos:
                                valid_ids.append(str(mi[0]))
                            text_arg = event.text.split(',')
                            if len(text_arg) == 0:
                                is_failed = True
                                await event.reply(
                                    'Please reply with "all" to ban all users displaying in the message\nor ban specified users: \n\n"<first user id>,<second user id>,<any number of user id>" (without bracket) '
                                )
                            #strictly check if id are int
                            for arg_t in text_arg:
                                try:
                                    arg_id = int(arg_t.strip())
                                except Exception as e:
                                    #print(str(e))
                                    is_failed = True
                                else:
                                    try:
                                        index = valid_ids.index(str(arg_id))
                                    except Exception as e:
                                        #id is not found inside the message
                                        #print('index error')
                                        is_failed = True
                                    else:
                                        ban_ids.append(str(arg_id))
                            if len(ban_ids) > 0 and is_failed == False:
                                #perform ban action
                                baned_num = 0
                                #await listener_client.start()
                                for ban_user in ban_ids:
                                    try:
                                        this_channel = await listener_client.get_input_entity(
                                            PeerChannel(manage_group_id))
                                        this_user = await listener_client.get_input_entity(
                                            PeerUser(ban_user))
                                        result = await listener_client(
                                            functions.channels.
                                            EditBannedRequest(
                                                channel=this_channel,
                                                user_id=this_user,
                                                banned_rights=types.
                                                ChatBannedRights(
                                                    until_date=datetime(
                                                        future_year, 6, 25),
                                                    view_messages=True,
                                                    send_messages=True,
                                                    send_media=True,
                                                    send_stickers=True,
                                                    send_gifs=True,
                                                    send_games=True,
                                                )))
                                    except Exception as e:
                                        if debug_mode == True:
                                            await event.reply('Error : ' +
                                                              str(e))
                                            print(str(e))
                                        else:
                                            await event.reply(
                                                'Error : please make sure user bot have permission to do so'
                                            )
                                    else:
                                        baned_num += 1
                                    await event.reply('Banned ' +
                                                      str(baned_num) +
                                                      ' users')
                                #await listener_client.disconnect()
                                #await event.reply('Banned '+str(len(ban_ids))+' users')
                            else:
                                await event.reply(
                                    'No valid user to ban.\n\nPlease reply with "all" to ban all users displaying in the  message\nor ban specified users:\n\n"<first user id>,<second user id>,<any number of user id>" (without bracket) '
                                )
                        except Exception as e:
                            print(str(e))

                else:
                    print('Error : no handler for this batch message')
                    await event.reply('Error : this message is expired')
            await os.remove(tg_config.setting['session_path'] +
                            str(event.from_id))

    else:
        if is_locked(event.from_id):
            if debug_mode == True:
                print(str(event.from_id) + 'LOCKED!')
            await event.reply(
                'Another process is running, please try again later.')
        else:
            Path(tg_config.setting['session_path'] +
                 str(event.from_id)).touch()
            #admin command , handle admin user's group command
            if event.text[0:1] == '_':
                text_arg = event.text.split()
                if text_arg[0] == '_help':
                    #help menu
                    help_menu = '---- Please read what you can do ----\n\n'
                    help_menu += '[_help] list help menu\n\n'
                    help_menu += '[_howtounban] how to unban user\n\n'
                    help_menu += '[_howtoban] how to ban user from cdrom report\n\n'
                    help_menu += '[_clear] clear all messages with <userbot>\n\n'
                    help_menu += '[_delmsg n] delete all messages of group before n days ago\n'
                    help_menu += 'HINTS: it may consume much time if there are too many messages. '
                    help_menu += 'Maximum ' + str(
                        max_delete_message
                    ) + ' messages for one batch delete action, you can run the command several times to delete ALL messages.\n'
                    help_menu += 'WARNING: 0 will delete messages of group before NOW\n\n'
                    #help_menu+='[_cdrom on n] enable the scheduler to run listing cdrom report every day at 23:00 for those who sent less than n messages\n\n'
                    #help_menu+='[_cdrom off] disable the scheduler to run listing cdrom report every day at 23:00\n\n'
                    help_menu += '[_cdrom] request of listing cdrom report, system admin will run it for you soon\n\n'
                    help_menu += '*  to ban user, reply to message in cdrom report\n'
                    await event.reply(help_menu)
                elif text_arg[0] == '_cdrom':
                    #cdrom report request
                    await event.reply(
                        'We will help run the report for you soon, please stop sending command for a moment.\nOr please ask server admin for help directly.'
                    )
                    #bot_listener_client = TelegramClient(tg_config.setting['session']['bot'], api_id, api_hash)
                    #await bot_listener_client.start()
                    try:
                        me_entity = await listener_client.get_input_entity(
                            user_bot_id)
                        sent_request = await listener_client(
                            functions.messages.SendMessageRequest(
                                peer=me_entity,
                                message=str(manage_group_id) +
                                ' cdrom request',
                                no_webpage=True))
                    except Exception as e:
                        if debug_mode == True:
                            print('Error : send message error' + str(e))
                    #await bot_listener_client.disconnect()

                elif text_arg[0] == '_howtounban':
                    try:
                        await event.reply(
                            'Clicked Removed Users\n\nhttps://ibb.co/kMwydJ3')
                        await event.reply(
                            'Swipe to unban\n\nhttps://ibb.co/zr9hGV4')
                    except Exception as e:
                        await event.reply('Error: ' + str(e))
                    #await listener_client.disconnect()
                elif text_arg[0] == '_howtoban':
                    try:
                        await event.reply(
                            'Reply to cdrom report message\n\nhttps://ibb.co/jyQCjGW'
                        )
                        await event.reply('Banned\n\nhttps://ibb.co/6XBZMck')
                    except Exception as e:
                        await event.reply('Error: ' + str(e))
                    #await listener_client.disconnect()
                elif text_arg[0] == '_clear':
                    #clear all message with user bot chat
                    #listener_client = TelegramClient(tg_config.setting['session']['runtime']+ '_' + str(manage_group_id), api_id, api_hash)
                    try:
                        #await listener_client.start()
                        target = await listener_client.get_input_entity(
                            event.chat_id)
                        await listener_client(
                            functions.messages.DeleteHistoryRequest(
                                peer=target,
                                max_id=0,
                                just_clear=True,
                                revoke=True))
                    except Exception as e:
                        await event.reply('Error: ' + str(e))
                    #await listener_client.disconnect()
                else:
                    if len(text_arg) > 1:
                        if text_arg[0] == '_delmsg':
                            #delete group messages
                            try:
                                day = int(text_arg[1])
                            except Exception as e:
                                await event.reply(
                                    'Please input number of days in integer (0 will delete all messages!).'
                                )
                            else:

                                if day >= 0:
                                    #listener_client = TelegramClient(tg_config.setting['session']['runtime']+ '_' + str(manage_group_id), api_id, api_hash)
                                    #await listener_client.start()
                                    if day > 0:
                                        n_datetime = datetime.now(
                                        ) - timedelta(days=day)
                                    else:
                                        n_datetime = datetime.now()
                                    start = True
                                    total = 0
                                    offset = 0
                                    message_ids = []
                                    message_selected = []
                                    #select messages to be deleted
                                    try:

                                        while start == True or total > 0:
                                            my_channel = await listener_client.get_input_entity(
                                                manage_group_id)
                                            to_be_deleted = await listener_client(
                                                functions.messages.
                                                GetHistoryRequest(
                                                    peer=my_channel,
                                                    offset_date=n_datetime,
                                                    offset_id=0,
                                                    add_offset=offset,
                                                    limit=100,
                                                    max_id=0,
                                                    min_id=0,
                                                    hash=0))
                                            offset += 100
                                            start = False
                                            total = len(to_be_deleted.messages)
                                            #print(to_be_deleted.stringify())
                                            message_selected.extend(
                                                to_be_deleted.messages)
                                            if len(message_selected
                                                   ) >= max_delete_message:
                                                break
                                    except Exception as e:
                                        await event.reply('Error: ' + str(e))
                                    else:
                                        if len(message_selected) == 0:
                                            await event.reply(
                                                'No message can be deleted.')
                                        else:
                                            for msg in message_selected:
                                                message_ids.append(msg.id)
                                                #print('---incoming--- ' + str(msg.id))
                                            try:
                                                deleted = await listener_client(
                                                    functions.channels.
                                                    DeleteMessagesRequest(
                                                        channel=my_channel,
                                                        id=message_ids))
                                            except Exception as e:
                                                await event.reply('Error :' +
                                                                  str(e))
                                            else:
                                                await event.reply(
                                                    str(deleted.pts_count) +
                                                    ' message(s) is/are deleted'
                                                )
                                    #await listener_client.disconnect()
                        else:
                            await event.reply('Invalid command.')
                    else:
                        await event.reply('Invalid command.')
            await os.remove(tg_config.setting['session_path'] +
                            str(event.from_id))
コード例 #11
0
async def _(event):
    # Space weirdness in regex required because argument is optional and other
    # commands start with ".lock"
    if event.fwd_from:
        return
    input_str = event.pattern_match.group("target")
    if input_str == "":
        await eor(
            event,
            "LockTypes -\n➟ bots\n➟ commands\n➟ forward\n➟ url\n➟ msg\n➟ media\n ➟ sticker\n➟ gif\n➟ gamee\n➟ ainline\n ➟ gpoll\n➟ adduser\n➟ cpin\n➟ changeinfo\n\nUse `.lock <locktypes>` to lock it.",
        )
    peer_id = event.chat_id
    if input_str in (("bots", "commands", "email", "forward", "url")):
        update_lock(peer_id, input_str, True)
        await eor(event, "Locked {}".format(input_str))
    else:
        msg = None
        media = None
        sticker = None
        gif = None
        gamee = None
        ainline = None
        gpoll = None
        adduser = None
        cpin = None
        changeinfo = None
        if input_str:
            if "msg" in input_str:
                msg = True
            if "media" in input_str:
                media = True
            if "sticker" in input_str:
                sticker = True
            if "gif" in input_str:
                gif = True
            if "gamee" in input_str:
                gamee = True
            if "ainline" in input_str:
                ainline = True
            if "gpoll" in input_str:
                gpoll = True
            if "adduser" in input_str:
                adduser = True
            if "cpin" in input_str:
                cpin = True
            if "changeinfo" in input_str:
                changeinfo = True
        banned_rights = types.ChatBannedRights(
            until_date=None,
            # view_messages=None,
            send_messages=msg,
            send_media=media,
            send_stickers=sticker,
            send_gifs=gif,
            send_games=gamee,
            send_inline=ainline,
            send_polls=gpoll,
            invite_users=adduser,
            pin_messages=cpin,
            change_info=changeinfo,
        )
        try:
            result = await borg(  # pylint:disable=E0602
                functions.messages.EditChatDefaultBannedRightsRequest(
                    peer=peer_id, banned_rights=banned_rights))
        except Exception as e:  # pylint:disable=C0103,W0703
            await eor(event, str(e))
        else:
            await eor(
                event,
                "Current Chat Default Permissions Changed Successfully, in API"
            )
コード例 #12
0
async def _(event):
    # Space weirdness in regex required because argument is optional and other
    # commands start with ".lock"
    if event.fwd_from:
        return
    input_str = event.pattern_match.group("target")
    peer_id = event.chat_id
    if input_str in (("bots", "commands", "email", "forward", "url")):
        update_lock(peer_id, input_str, True)
        await event.edit("Bloccati {}".format(input_str))
    else:
        msg = None
        media = None
        sticker = None
        gif = None
        gamee = None
        ainline = None
        gpoll = None
        adduser = None
        cpin = None
        changeinfo = None
        if input_str:
            if "msg" in input_str:
                msg = True
            if "media" in input_str:
                media = True
            if "sticker" in input_str:
                sticker = True
            if "gif" in input_str:
                gif = True
            if "gamee" in input_str:
                gamee = True
            if "ainline" in input_str:
                ainline = True
            if "gpoll" in input_str:
                gpoll = True
            if "adduser" in input_str:
                adduser = True
            if "cpin" in input_str:
                cpin = True
            if "changeinfo" in input_str:
                changeinfo = True
        banned_rights = types.ChatBannedRights(
            until_date=None,
            # view_messages=None,
            send_messages=msg,
            send_media=media,
            send_stickers=sticker,
            send_gifs=gif,
            send_games=gamee,
            send_inline=ainline,
            send_polls=gpoll,
            invite_users=adduser,
            pin_messages=cpin,
            change_info=changeinfo,
        )
        try:
            result = await borg(  # pylint:disable=E0602
                functions.messages.EditChatDefaultBannedRightsRequest(
                    peer=peer_id, banned_rights=banned_rights))
        except Exception as e:  # pylint:disable=C0103,W0703
            await event.edit(str(e))
        else:
            await event.edit(
                "Permessi Del Gruppo cambiati con Successo, in API")
コード例 #13
0
async def _(event):
    # Düzenli ifadede boşluk tuhaflığı gereklidir çünkü bağımsız değişken isteğe bağlıdır ve diğer
    # komut ".lock" ile başlar
    if event.fwd_from:
        return
    input_str = event.pattern_match.group("hedef")
    peer_id = event.chat_id
    if input_str in (("bots", "commands", "email", "forward", "url")):
        update_lock(peer_id, input_str, True)
        await event.edit("Kilitli {}".format(input_str))
    else:
        msg = None
        media = None
        sticker = None
        gif = None
        gamee = None
        ainline = None
        gpoll = None
        adduser = None
        cpin = None
        changeinfo = None
        if input_str:
            if "msg" in input_str:
                msg = True
            if "media" in input_str:
                media = True
            if "sticker" in input_str:
                sticker = True
            if "gif" in input_str:
                gif = True
            if "gamee" in input_str:
                gamee = True
            if "ainline" in input_str:
                ainline = True
            if "gpoll" in input_str:
                gpoll = True
            if "adduser" in input_str:
                adduser = True
            if "cpin" in input_str:
                cpin = True
            if "changeinfo" in input_str:
                changeinfo = True
        banned_rights = types.ChatBannedRights(
            until_date=None,
            # view_messages=None,
            send_messages=msg,
            send_media=media,
            send_stickers=sticker,
            send_gifs=gif,
            send_games=gamee,
            send_inline=ainline,
            send_polls=gpoll,
            invite_users=adduser,
            pin_messages=cpin,
            change_info=changeinfo,
        )
        try:
            result = await borg(  # pylint:disable=E0602
                functions.messages.EditChatDefaultBannedRightsRequest(
                    peer=peer_id, banned_rights=banned_rights))
        except Exception as e:  # pylint:disable=C0103,W0703
            await event.edit(str(e))
        else:
            await event.edit(
                "API'da Mevcut Sohbet Varsayılan İzinleri Başarıyla Değiştirildi"
            )