Exemplo n.º 1
0
def kang(client, message):
    myacc = TEMP_SETTINGS['ME']
    kanger = myacc.username or myacc.first_name
    if myacc.username:
        kanger = f'@{kanger}'
    args = extract_args(message)

    reply = message.reply_to_message
    if not reply:
        edit(message, f'`{get_translation("stickerUsage")}`')
        return

    anim = False
    media = None

    if reply.photo or reply.document or reply.sticker:
        edit(message, f'`{choice(DIZCILIK)}`')
        anim = reply.sticker and reply.sticker.is_animated
        media = download_media_wc(reply, sticker_orig=anim)
    else:
        edit(message, f'`{get_translation("stickerError")}`')
        return

    if len(args) < 1:
        args = '1'

    emoji = '🤤'
    pack = 1

    for item in args.split():
        if item.isdigit():
            pack = int(item)
            args = args.replace(item, '').strip()
        elif 'e=' in item.lower():
            emoji = item.replace('e=', '')
            args = args.replace(item, '').strip()

    pname = (
        PACKNAME.replace(' ', '')
        if PACKNAME
        else f'a{myacc.id}_by_{myacc.username}_{pack}'
    )
    pnick = PACKNICK or f"{kanger}'s UserBot pack {pack}"

    limit = '50' if anim else '120'

    def pack_created(name):
        try:
            set_name = InputStickerSetShortName(short_name=name)
            set = GetStickerSet(stickerset=set_name)
            client.send(data=set)
            return True
        except BaseException as e:
            return False

    def create_new(conv, pname, pnick):
        cmd = f'/new{"animated" if anim else "pack"}'

        try:
            send_recv(conv, cmd)
        except Exception as e:
            raise e
        msg = send_recv(conv, pnick)
        if msg.text == 'Invalid pack selected.':
            pack += 1
            return create_new(conv)
        msg = send_recv(conv, media, doc=True)
        if 'Sorry, the file type is invalid.' in msg.text:
            edit(message, f'`{get_translation("stickerError")}`')
            return
        send_recv(conv, emoji)
        send_recv(conv, '/publish')
        if anim:
            send_recv(conv, f'<{pnick}>')
        send_recv(conv, '/skip')
        send_recv(conv, pname)

    def add_exist(conv, pack, pname, pnick):
        try:
            send_recv(conv, '/addsticker')
        except Exception as e:
            raise e

        status = send_recv(conv, pname)

        if limit in status.text:
            pack += 1
            pname = (
                PACKNAME.replace(' ', '')
                if PACKNAME
                else f'a{myacc.id}_by_{myacc.username}_{pack}'
            )
            pnick = PACKNICK or f"{kanger}'s UserBot pack {pack}"
            edit(message, get_translation('packFull', ['`', '**', str(pack)]))
            if pack_created(pname):
                return add_exist(conv, pack, pname, pnick)
            else:
                return create_new(conv, pname, pnick)

        send_recv(conv, media, doc=True)
        send_recv(conv, emoji)
        send_recv(conv, '/done')
        return True

    if anim:
        pname += '_anim'
        pnick += ' (Animated)'
    else:
        if not reply.sticker:
            media = resizer(media)

    with PyroConversation(client, 'Stickers') as conv:
        send_recv(conv, '/cancel')
        if pack_created(pname):
            ret = add_exist(conv, pack, pname, pnick)
            if not ret:
                return
        else:
            create_new(conv, pname, pnick)

    edit(message, get_translation('stickerAdded', ['`', pname]))
Exemplo n.º 2
0
def kang(client, message):
    myacc = me[0]
    kanger = myacc.username or myacc.first_name
    if myacc.username:
        kanger = f'@{kanger}'
    args = extract_args(message)

    reply = message.reply_to_message
    if not reply:
        edit(message, f'`{get_translation("stickerUsage")}`')
        return

    anim = False
    media = None

    if (reply.photo or reply.document or reply.sticker):
        edit(message, f'`{choice(DIZCILIK)}`')
        anim = reply.sticker and reply.sticker.is_animated
        media = download_media_wc(reply, sticker_orig=anim)
    else:
        edit(message, f'`{get_translation("stickerError")}`')
        return

    if len(args) < 1:
        args = 1

    emoji = '🤤'

    if ' ' in str(args):
        emoji, args = args.split(' ', 1)

    pack = 1 if not str(args).isdigit() else int(args)

    pname = PACKNAME.replace(
        ' ', '') if PACKNAME else f'a{myacc.id}_by_{myacc.username}_{pack}'
    pnick = PACKNICK or f"{kanger}'s UserBot pack {pack}"

    limit = '50' if anim else '120'

    def pack_created():
        created = get(f'https://telegram.me/addstickers/{pname}')
        created = (('A <strong>Telegram</strong> user has created the '
                    '<strong>Sticker&nbsp;Set</strong>') not in created.text)
        return created

    def create_new(conv, pack):
        cmd = f'/new{"animated" if anim else "pack"}'

        try:
            send_recv(conv, cmd)
        except Exception as e:
            raise e
        msg = send_recv(conv, pnick)
        if msg.text == 'Invalid pack selected.':
            pack += 1
            return create_new(conv)
        msg = send_recv(conv, media, doc=True)
        if 'Sorry, the file type is invalid.' in msg.text:
            edit(message, f'`{get_translation("stickerError")}`')
            return
        send_recv(conv, emoji)
        send_recv(conv, '/publish')
        if anim:
            send_recv(conv, f'<{pnick}>')
        send_recv(conv, '/skip')
        send_recv(conv, pname)

    def add_exist(conv, pack, pname, pnick):
        try:
            send_recv(conv, '/addsticker')
        except Exception as e:
            raise e

        status = send_recv(conv, pname)

        if limit in status.text:
            pack += 1
            pname = PACKNAME.replace(
                ' ',
                '') if PACKNAME else f'a{myacc.id}_by_{myacc.username}_{pack}'
            pnick = PACKNICK or f"{kanger}'s UserBot pack {pack}"
            edit(message, get_translation('packFull', ['`', '**', str(pack)]))
            return add_exist(conv, pack, pname, pnick)

        send_recv(conv, media, doc=True)
        send_recv(conv, emoji)
        send_recv(conv, '/done')
        return True

    if anim:
        pname += '_anim'
        pnick += ' (Animated)'
    else:
        if not reply.sticker:
            media = resizer(media)

    with PyroConversation(client, 'Stickers') as conv:
        if pack_created():
            ret = add_exist(conv, pack, pname, pnick)
            if not ret:
                return
        else:
            create_new(conv, pack)

    edit(message, get_translation('stickerAdded', ['`', pname]))