Esempio n. 1
0
def mute_channels(client):
    for dialog in client.iter_dialogs():
        if dialog.is_channel:  # Process channels only
            if channel_is_muted(client, dialog):
                print(dialog.title + " channel is already muted")
                continue

            result = client(
                UpdateNotifySettingsRequest(peer=dialog,
                                            settings=InputPeerNotifySettings(
                                                show_previews=False,
                                                mute_until=datetime.datetime(
                                                    2038, 1, 1),
                                                sound=None)))

            if result:
                print(dialog.title + " channel is muted until 2038/01/01 !")
            else:
                print(dialog.title + " channel is skipped !")
Esempio n. 2
0
async def kang(event):
    """ Function for .kang command, create a sticker pack and add stickers. """
    await event.edit('`Kanging...`')
    user = await bot.get_me()
    pack_username = ''
    if not user.username:
        try:
            user.first_name.decode('ascii')
            pack_username = user.first_name
        except UnicodeDecodeError: # User's first name isn't ASCII, use ID instead
            pack_username = user.id
    else: pack_username = user.username

    textx = await event.get_reply_message()
    emoji = event.pattern_match.group(2)
    number = int(event.pattern_match.group(3) or 1) # If no number specified, use 1
    new_pack = False

    if textx.photo or textx.sticker: message = textx
    elif event.photo or event.sticker: message = event
    else:
        await event.edit("`You need to send/reply to a sticker/photo to be able to kang it!`")
        return

    sticker = io.BytesIO()
    await bot.download_media(message, sticker)
    sticker.seek(0)

    if not sticker:
        await event.edit("`Couldn't download sticker! Make sure you send a proper sticker/photo.`")
        return

    is_anim = message.file.mime_type == "application/x-tgsticker"
    if not is_anim:
        img = await resize_photo(sticker)
        sticker.name = "sticker.png"
        sticker.seek(0)
        img.save(sticker, "PNG")

    # The user didn't specify an emoji...
    if not emoji:
        if message.file.emoji: # ...but the sticker has one
            emoji = message.file.emoji
        else: # ...and the sticker doesn't have one either
            emoji = "🤔"

    packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
    packtitle = (f"@{user.username or user.first_name}' - Naklejki "
                f"{number}{' animated' if is_anim else ''}")
    response = urllib.request.urlopen(
            urllib.request.Request(f'http://t.me/addstickers/{packname}'))
    htmlstr = response.read().decode("utf8").split('\n')
    new_pack = PACK_DOESNT_EXIST in htmlstr

    # Mute Stickers bot to ensure user doesn't get notification spam
    muted = await bot(UpdateNotifySettingsRequest(
        peer='t.me/Stickers',
        settings=InputPeerNotifySettings(mute_until=2**31-1)) # Mute forever
    )
    if not muted: # Tell the user just in case, this may rarely happen
        await event.edit(
            "`Paperplane couldn't mute the Stickers bot, beware of notification spam.`")

    if new_pack:
        await event.edit("`This Paperplane Sticker Pack doesn't exist! Creating a new pack...`")
        await newpack(is_anim, sticker, emoji, packtitle, packname)
    else:
        async with bot.conversation('t.me/Stickers') as conv:
            # Cancel any pending command
            await conv.send_message('/cancel')
            await conv.get_response()

            # Send the add sticker command
            await conv.send_message('/addsticker')
            await conv.get_response()

            # Send the pack name
            await conv.send_message(packname)
            x = await conv.get_response()

            # Check if the selected pack is full
            while x.text == PACK_FULL:
                # Switch to a new pack, create one if it doesn't exist
                number += 1
                packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
                packtitle = (f"@{user.username or user.first_name} - Naklejki "
                            f"{number}{' animated' if is_anim else ''}")

                await event.edit(
                    f"`Switching to Pack {number} due to insufficient space in Pack {number-1}.`"
                )

                await conv.send_message(packname)
                x = await conv.get_response()
                if x.text == "Invalid pack selected.": # That pack doesn't exist
                    await newpack(is_anim, sticker, emoji, packtitle, packname)

                    # Read all unread messages
                    await bot.send_read_acknowledge('t.me/Stickers')
                    # Unmute Stickers bot back
                    muted = await bot(UpdateNotifySettingsRequest(
                        peer='t.me/Stickers',
                        settings=InputPeerNotifySettings(mute_until=None))
                    )

                    await event.edit(
                        f"`Sticker added to pack {number}{'(animated)' if is_anim else ''} with "
                        f"{emoji} as the emoji! "
                        f"This pack can be found `[here](t.me/addstickers/{packname})",
                        parse_mode='md')
                    return

            # Upload the sticker file
            if is_anim:
                upload = await message.client.upload_file(sticker, file_name="AnimatedSticker.tgs")
                await conv.send_file(upload, force_document=True)
            else:
                sticker.seek(0)
                await conv.send_file(sticker, force_document=True)
            await conv.get_response()

            # Send the emoji
            await conv.send_message(emoji)
            await conv.get_response()

            # Finish editing the pack
            await conv.send_message('/done')
            await conv.get_response()

    # Read all unread messages
    await bot.send_read_acknowledge('t.me/Stickers')
    # Unmute Stickers bot back
    muted = await bot(UpdateNotifySettingsRequest(
        peer='t.me/Stickers',
        settings=InputPeerNotifySettings(mute_until=None))
    )

    await event.edit(
        f"`Sticker added to pack {number}{'(animated)' if is_anim else ''} with "
        f"{emoji} as the emoji! "
        f"This pack can be found `[here](t.me/addstickers/{packname})",
        parse_mode='md')
Esempio n. 3
0
async def kangpack(event):
    await event.edit("`Kanging the whole pack...`")
    user = await bot.get_me()
    pack_username = ""
    if not user.username:
        try:
            user.first_name.decode("ascii")
            pack_username = user.first_name
        except UnicodeDecodeError:  # User's first name isn't ASCII, use ID instead
            pack_username = user.id
    else:
        pack_username = user.username

    textx = await event.get_reply_message()

    if not textx.sticker:
        await event.edit(
            "`You need to reply to a sticker to be able to kang the whole pack!`"
        )
        return

    sticker_set = textx.file.sticker_set
    stickers = await event.client(
        GetStickerSetRequest(stickerset=InputStickerSetID(
            id=sticker_set.id, access_hash=sticker_set.access_hash)))
    is_anim = textx.file.mime_type == "application/x-tgsticker"

    number = event.pattern_match.group(2) or 1
    new_pack = False
    while not new_pack:
        packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
        packtitle = (f"@{user.username or user.first_name}'s Paperplane Pack "
                     f"{number}{' animated' if is_anim else ''}")
        response = urllib.request.urlopen(
            urllib.request.Request(f"http://t.me/addstickers/{packname}"))
        htmlstr = response.read().decode("utf8").split("\n")
        new_pack = PACK_DOESNT_EXIST in htmlstr
        if not new_pack:
            if event.pattern_match.group(2):
                await event.edit(
                    "`This pack doesn't exist! Specify another number or omit the argument to let "
                    "Paperplane get the lowest available pack number automatically.`"
                )
                return
            number += 1

    # Mute Stickers bot to ensure user doesn't get notification spam
    muted = await bot(
        UpdateNotifySettingsRequest(
            peer="t.me/Stickers",
            settings=InputPeerNotifySettings(mute_until=2**31 - 1),
        )  # Mute forever
    )
    if not muted:  # Tell the user just in case, this may rarely happen
        await event.edit(
            "`Paperplane couldn't mute the Stickers bot, beware of notification spam.`"
        )

    async with bot.conversation("Stickers") as conv:
        # Cancel any pending command
        await conv.send_message("/cancel")
        await conv.get_response()

        # Send new pack command
        if is_anim:
            await conv.send_message("/newanimated")
        else:
            await conv.send_message("/newpack")
        await conv.get_response()

        # Give the pack a name
        await conv.send_message(packtitle)
        await conv.get_response()

    for sticker in stickers.documents:
        async with bot.conversation("Stickers") as conv2:
            emoji = sticker.attributes[1].alt
            # Upload sticker file
            if is_anim:
                sticker_dl = io.BytesIO()
                await bot.download_media(sticker, sticker_dl)
                sticker_dl.seek(0)
                upload = await bot.upload_file(sticker_dl,
                                               file_name="AnimatedSticker.tgs")
                await conv2.send_file(upload, force_document=True)
            else:
                await conv2.send_file(sticker, force_document=True)
            await conv2.get_response()

            # Send the emoji
            await conv2.send_message(emoji)
            await conv2.get_response()

    async with bot.conversation("Stickers") as conv:
        # Publish the pack
        await conv.send_message("/publish")
        if is_anim:
            await conv.get_response()
            await conv.send_message(f"<{packtitle}>")
        await conv.get_response()

        # Skip pack icon selection
        await conv.send_message("/skip")
        await conv.get_response()

        # Send packname
        await conv.send_message(packname)
        await conv.get_response()

    # Read all unread messages
    await bot.send_read_acknowledge("t.me/Stickers")
    # Unmute Stickers bot back
    muted = await bot(
        UpdateNotifySettingsRequest(
            peer="t.me/Stickers",
            settings=InputPeerNotifySettings(mute_until=None)))

    await event.edit(
        f"`Sticker pack {number}{' (animated)' if is_anim else ''} has been created!\n"
        f"It can be found` [here](t.me/addstickers/{packname})`.`",
        parse_mode="md",
    )
Esempio n. 4
0
async def kang(event):
    await event.edit(f"`{PLUGIN_MESAJLAR['dızcı']}`")
    user = await bot.get_me()
    pack_username = ''
    if not user.username:
        try:
            user.first_name.decode('ascii')
            pack_username = user.first_name
        except UnicodeDecodeError:  # User's first name isn't ASCII, use ID instead
            pack_username = user.id
    else:
        pack_username = user.username

    textx = await event.get_reply_message()
    emoji = event.pattern_match.group(2)
    number = int(event.pattern_match.group(3)
                 or 1)  # If no number specified, use 1
    new_pack = False

    if textx.photo or textx.sticker: message = textx
    elif event.photo or event.sticker: message = event
    else:
        await event.edit(LANG['GIVE_STICKER'])
        return

    sticker = io.BytesIO()
    await bot.download_media(message, sticker)
    sticker.seek(0)

    if not sticker:
        await event.edit(LANG['FAIL_DOWNLOAD'])
        return

    is_anim = message.file.mime_type == "application/x-tgsticker"
    if not is_anim:
        img = await resize_photo(sticker)
        sticker.name = "sticker.png"
        sticker.seek(0)
        img.save(sticker, "PNG")

    # The user didn't specify an emoji...
    if not emoji:
        if message.file.emoji:  # ...but the sticker has one
            emoji = message.file.emoji
        else:  # ...and the sticker doesn't have one either
            emoji = choice(['❤️', '😆', '🤰🏻', '😳', '💗', '🥺', '🤔'])

    packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
    packtitle = (f"@{user.username or user.first_name} {PAKET_ISMI} "
                 f"{number}{' animasyonlu' if is_anim else ''}")
    response = urllib.request.urlopen(
        urllib.request.Request(f'http://t.me/addstickers/{packname}'))
    htmlstr = response.read().decode("utf8").split('\n')
    new_pack = PACK_DOESNT_EXIST in htmlstr

    if new_pack:
        await event.edit(LANG['NEW_PACK'])
        await newpack(is_anim, sticker, emoji, packtitle, packname, message)
    else:
        async with bot.conversation("Stickers") as conv:
            # Cancel any pending command
            await conv.send_message('/cancel')
            await conv.get_response()

            # Send the add sticker command
            await conv.send_message('/addsticker')
            await conv.get_response()

            # Send the pack name
            await conv.send_message(packname)
            x = await conv.get_response()

            # Check if the selected pack is full
            while x.text == PACK_FULL:
                # Switch to a new pack, create one if it doesn't exist
                number += 1
                packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
                packtitle = (
                    f"@{user.username or user.first_name} {PAKET_ISMI} "
                    f"{number}{' animated' if is_anim else ''}")

                await event.edit(LANG['TOO_STICKERS'].format(number))

                await conv.send_message(packname)
                x = await conv.get_response()
                if x.text == "Invalid pack selected.":  # That pack doesn't exist
                    await newpack(is_anim, sticker, emoji, packtitle, packname)

                    # Read all unread messages
                    await bot.send_read_acknowledge("stickers")
                    # Unmute Stickers bot back
                    muted = await bot(
                        UpdateNotifySettingsRequest(
                            peer=429000,
                            settings=InputPeerNotifySettings(mute_until=None)))

                    await event.edit(
                        f"`Sticker {number}{'(animasyonlu)' if is_anim else ''} sayılı pakete eklendi, "
                        f"{emoji} emojisi ile birlikte! "
                        f"Paket `[burada](t.me/addstickers/{packname})` Ulaşılabilir...`",
                        parse_mode='md')
                    return

            # Upload the sticker file
            if is_anim:
                upload = await message.client.upload_file(
                    sticker, file_name="AnimatedSticker.tgs")
                await conv.send_file(upload, force_document=True)
            else:
                sticker.seek(0)
                await conv.send_file(sticker, force_document=True)
            kontrol = await conv.get_response()

            if "Sorry, the image dimensions are invalid." in kontrol.text:
                await event.edit(
                    "`Sticker's kabul etmedi. İkinci yöntem deneniyor...`")
                try:
                    await bot.send_file("@ezstickerbot",
                                        message,
                                        force_document=True)
                except YouBlockedUserError:
                    return await event.edit(
                        "`Lütfen` @EzStickerBot `engelini açın ve tekrar deneyin!`"
                    )

                try:
                    response = await conv.wait_event(
                        events.NewMessage(incoming=True, from_users=350549033))
                    if "Please temporarily use" in response.text:
                        await bot.send_file("@EzStickerBotBackupBot",
                                            message,
                                            force_document=True)
                        response = await conv.wait_event(
                            events.NewMessage(incoming=True,
                                              from_users=891811251))

                    await bot.send_read_acknowledge(350549033)
                    await event.client.forward_messages(
                        "stickers", response.message, 350549033)
                except:
                    await bot.send_file("@EzStickerBotBackupBot",
                                        message,
                                        force_document=True)
                    response = await conv.wait_event(
                        events.NewMessage(incoming=True, from_users=891811251))
                    await bot.send_read_acknowledge(891811251)
                    await event.client.forward_messages(
                        "stickers", response.message, 891811251)

            # Send the emoji
            await conv.send_message(emoji)
            await conv.get_response()

            # Finish editing the pack
            await conv.send_message('/done')
            await conv.get_response()

    # Read all unread messages
    await bot.send_read_acknowledge(429000)
    # Unmute Stickers bot back
    muted = await bot(
        UpdateNotifySettingsRequest(
            peer=429000, settings=InputPeerNotifySettings(mute_until=None)))

    await event.edit(
        f"`Sticker {number}{'(animasyonlu)' if is_anim else ''} sayılı pakete eklendi, "
        f"{emoji} emojisi ile birlikte! "
        f"Paket `[burada](t.me/addstickers/{packname})` Ulaşılabilir...`",
        parse_mode='md')
Esempio n. 5
0
async def kang(event):
    """
    <b>param:</b> <code>emoji</code>
    <b>return:</b> <i>Sticker Pack link including the kanged sticker</i>
    """
    if not event.is_reply:
        await event.edit("There's no image given for me to kang!")
        return
    rep_msg = await event.get_reply_message()
    file = rep_msg.photo or rep_msg.document

    if has_image(file):
        st_emoji = event.args.emoji or "🤔"
        if st_emoji not in (list(emoji.EMOJI_UNICODE.values())):
            await event.edit("Not a valid emoji!")
            return

        user = await event.get_sender()
        packname = user.username or user.first_name + "'s sticker pack!"
        packshort = "tg_companion_" + str(user.id)
        await event.edit("Processing sticker! Please wait...")
        async with event.client.conversation('Stickers') as conv:
            until_time = (datetime.datetime.now() +
                          datetime.timedelta(minutes=1)).timestamp()
            await event.client(
                UpdateNotifySettingsRequest(peer="Stickers",
                                            settings=InputPeerNotifySettings(
                                                show_previews=False,
                                                mute_until=until_time)))

            try:
                await conv.send_message("/cancel")
            except YouBlockedUserError:
                await event.reply(
                    "You blocked the sticker bot. Please unblock it and try again"
                )
                return

            file = await event.client.download_file(file)
            with BytesIO(file) as mem_file, BytesIO() as sticker:
                resize_image(mem_file, (512, 512), sticker)
                sticker.seek(0)
                uploaded_sticker = await event.client.upload_file(
                    sticker, file_name="sticker.png")

            try:
                await event.client(
                    GetStickerSetRequest(InputStickerSetShortName(packname)))
                new_pack = False
            except StickersetInvalidError:
                new_pack = True

            if new_pack is False:
                await conv.send_message("/newpack")
                response = await conv.get_response()
                if not response.text.startswith("Yay!"):
                    await event.edit(response.text)
                    return

                await conv.send_message(packname)
                response = await conv.get_response()
                if not response.text.startswith("Alright!"):
                    await event.edit(response.text)
                    return

                await conv.send_file(InputMediaUploadedDocument(
                    file=uploaded_sticker,
                    mime_type='image/png',
                    attributes=[DocumentAttributeFilename("sticker.png")]),
                                     force_document=True)
                await conv.send_message(st_emoji)
                await conv.send_message("/publish")
                await conv.send_message("/skip")
                await conv.send_message(packshort)
                response = conv.get_response()
            else:
                await conv.send_message("/addsticker")
                await conv.send_message(packshort)
                await conv.send_file(InputMediaUploadedDocument(
                    file=uploaded_sticker,
                    mime_type='image/png',
                    attributes=[DocumentAttributeFilename("sticker.png")]),
                                     force_document=True)
                await conv.send_message(st_emoji)
                await conv.send_message("/done")
        await event.edit(
            "Sticker added! Your pack can be found [here](https://t.me/addstickers/{})"
            .format(packshort))
    else:
        await event.edit("Not a valid media entity!")
Esempio n. 6
0
            emoji = message.file.emoji
        else: # ...and the sticker doesn't have one either
            emoji = "🤔"

    packname = f"a{user.id}_by_{pack_username}_{number}{'_anim' if is_anim else ''}"
    packtitle = (f"@{user.username or user.first_name}'s remix Pack "
                f"{number}{' animated' if is_anim else ''}")
    response = urllib.request.urlopen(
            urllib.request.Request(f'http://t.me/addstickers/{packname}'))
    htmlstr = response.read().decode("utf8").split('\n')
    new_pack = PACK_DOESNT_EXIST in htmlstr

    # Mute Stickers bot to ensure user doesn't get notification spam
    muted = await bot(UpdateNotifySettingsRequest(
        peer='t.me/Stickers',
        settings=InputPeerNotifySettings(mute_until=2**31-1)) # Mute forever
    )
    if not muted: # Tell the user just in case, this may rarely happen
        await event.edit(
            "`remix couldn't mute the Stickers bot, beware of notification spam.`")

    if new_pack:
        await event.edit("`This remix Sticker Pack doesn't exist! Creating a new pack...`")
        await newpack(is_anim, sticker, emoji, packtitle, packname)
    else:
        async with bot.conversation('t.me/Stickers') as conv:
            # Cancel any pending command
            await conv.send_message('/cancel')
            await conv.get_response()

            # Send the add sticker command