Exemple #1
0
def newpack(msg, user, tempsticker, emoji, packname, packid, sendreply,
            replymsg, bot):
    try:
        stickerfile = open(tempsticker, 'rb')
        replymsg.edit_text(s.NEW_PACK, parse_mode=ParseMode.MARKDOWN)
        if tempsticker.endswith('png'):
            bot.createNewStickerSet(user.id,
                                    packid,
                                    packname,
                                    png_sticker=stickerfile,
                                    emojis=emoji,
                                    timeout=9999)
        else:
            bot.createNewStickerSet(user.id,
                                    packid,
                                    packname,
                                    tgs_sticker=stickerfile,
                                    emojis=emoji,
                                    timeout=9999)
        default = 0 if sql.get_default_pack(user.id) else 1
        sql.new_pack(packid, user.id, default, packname)
        stickerfile.close()
    except TelegramError as e:
        if e.message == "Sticker set name is already occupied":
            replymsg.edit_text(s.PACK_ALREADY_EXISTS.format(packid),
                               parse_mode=ParseMode.MARKDOWN)
        if e.message == "Internal Server Error: created sticker set not found (500)":  # throws this error but pack gets created anyway. idk.
            replymsg.edit_text(s.NEW_PACK_CREATED.format(packid),
                               parse_mode=ParseMode.MARKDOWN)
            default = 0 if sql.get_default_pack(user.id) else 1
            sql.new_pack(packid, user.id, default, packname)
        elif e.message == "Sticker set name invalid" and sendreply:
            replymsg.edit_text(s.INVALID_PACKNAME)
        elif e.message == "Peer_id_invalid":
            kb = [[
                InlineKeyboardButton(text="Start", url=f"t.me/{bot.username}")
            ]]
            replymsg.edit_text(s.INVALID_PEER_ID,
                               reply_markup=InlineKeyboardMarkup(kb))
        else:
            replymsg.edit_text(s.NEWPACK_ERROR)
            print(e)
    else:
        if sendreply:
            replymsg.edit_text(s.NEW_PACK_CREATED.format(packid),
                               parse_mode=ParseMode.MARKDOWN)
    finally:
        reply(msg, None, replymsg)
Exemple #2
0
def mypacks(update, context):
    msg = update.effective_message
    user = update.effective_user
    packs = sql.list_packs(user.id)
    defpack = sql.get_default_pack(user.id)
    packlist = f"{user.first_name}'s steal pack list :\n"
    if checkpacks(context.bot, packs):
        packs = sql.list_packs(user.id)
    blank = packlist
    count = 0
    for pack in packs:
        count += 1
        if pack == defpack[0]:
            packlist += f"\n*{count}.* [{pack[3]}](t.me/addstickers/{pack[0]}) ✓"
        else:
            packlist += f"\n*{count}.* [{pack[3]}](t.me/addstickers/{pack[0]})"
    if packlist == blank:
        replymsg = msg.reply_text(s.NO_STOLEN_PACKS)
    else:
        replymsg = msg.reply_markdown(packlist)
    reply(msg, None, replymsg)
Exemple #3
0
def switch(update, context):
    user = update.effective_user
    msg = update.effective_message
    if not context.args:
        reply(msg, s.SWITCH_INVALID_INPUT)
        return
    packs = sql.list_packs(user.id)
    if not packs:
        reply(msg, s.NO_STOLEN_PACKS)
        return
    if checkpacks(context.bot, packs):
        packs = sql.list_packs(user.id)
    if context.args[-1].isdigit():
        try:
            newdefpack = packs[int(context.args[-1]) - 1]
            defpack = sql.get_default_pack(user.id)
        except:
            reply(msg, s.SWITCH_PACK_DOESNT_EXIST)
            return
        if defpack == newdefpack:
            reply(msg, s.SWITCH_ALREADY_DEFAULT.format(newdefpack[3]))
        else:
            try:
                sql.remove_default(user.id)
                sql.set_default_by_id(newdefpack[0])
                reply(msg, s.SWITCH_CHANGED_DEFAULT.format(newdefpack[3]))
            except:
                reply(msg, s.SWITCH_INDEX_ERROR)
    else:
        arg = ' '.join(context.args)
        if not sql.get_pack_by_name(arg.lower(), user.id):
            reply(msg, s.SWITCH_PACK_DOESNT_EXIST)
            return
        try:
            sql.remove_default(user.id)
            sql.set_default_by_name(arg.lower(), user.id)
            reply(msg, s.SWITCH_CHANGED_DEFAULT.format(arg))
        except:
            reply(msg, s.SWITCH_PACKNAME_ERROR)
Exemple #4
0
def steal(update, context):
    msg = update.effective_message
    user = update.effective_user
    tempsticker = f"{str(user.id)}.png"
    if not msg.reply_to_message:
        reply(msg, s.STEAL_NOT_REPLY)
        return

    emoji = "🤔"
    defpack = sql.get_default_pack(user.id)
    if defpack: packname = defpack[0][3]
    else: packname = user.first_name[:35] + "'s Stolen Pack"
    if context.args:
        if len(context.args[-1][-1].encode('utf-8')) == 1:
            packname = ' '.join(context.args)
            if msg.reply_to_message.sticker:
                emoji = msg.reply_to_message.sticker.emoji
        else:
            emoji = str(context.args[-1])
            if len(context.args) > 1:
                packname = ' '.join(context.args[:-1])

    useridhash = hashlib.sha1(bytearray(user.id)).hexdigest()
    packnamehash = hashlib.sha1(bytearray(
        packname.lower().encode('utf-8'))).hexdigest()
    packid = f'K{packnamehash[:10]}{useridhash[:10]}_by_{context.bot.username}'
    replymsg = msg.reply_text(s.STEALING, parse_mode=ParseMode.MARKDOWN)

    try:
        if msg.reply_to_message.sticker:
            if msg.reply_to_message.sticker.is_animated:
                tempsticker = tempsticker[:-3] + 'tgs'
            file_id = msg.reply_to_message.sticker.file_id
        elif msg.reply_to_message.photo:
            file_id = msg.reply_to_message.photo[-1].file_id
        elif msg.reply_to_message.document:
            file_id = msg.reply_to_message.document.file_id
        context.bot.get_file(file_id).download(tempsticker)
        processimage(tempsticker)
        stickerfile = open(tempsticker, 'rb')
        if tempsticker.endswith('png'):
            context.bot.addStickerToSet(user_id=user.id,
                                        name=packid,
                                        png_sticker=stickerfile,
                                        emojis=emoji)
        else:
            context.bot.addStickerToSet(user_id=user.id,
                                        name=packid,
                                        tgs_sticker=stickerfile,
                                        emojis=emoji)
        replymsg.edit_text(s.STEAL_SUCESSFUL.format(packid),
                           parse_mode=ParseMode.MARKDOWN)
    except OSError as e:
        replymsg.edit_text(s.REPLY_NOT_STICKER_IMAGE)
    except TelegramError as e:
        if e.message == "Stickerset_invalid":
            newpack(msg, user, tempsticker, emoji, packname, packid, True,
                    replymsg, context.bot)
        elif e.message == "Sticker_tgs_notgs":
            replymsg.edit_text(s.UNANIMATED_IN_ANIMATED)
        elif e.message == "Sticker_png_nopng":
            replymsg.edit_text(s.ANIMATED_IN_UNANIMATED)
        elif e.message == "Invalid sticker emojis":
            replymsg.edit_text(s.INVALID_EMOJI)
        elif e.message == "Sticker set name invalid":
            replymsg.edit_text(s.INVALID_PACKNAME)
        elif e.message == "Stickers_too_much":
            replymsg.edit_text(s.PACK_LIMIT_EXCEEDED)
        elif e.message == "Internal Server Error: sticker set not found (500)":
            replymsg.edit_text(s.STEAL_SUCESSFUL.format(packid),
                               parse_mode=ParseMode.MARKDOWN)
        else:
            replymsg.edit_text(s.STEAL_ERROR)
            print(e.message)
    finally:
        stickerfile.close()
        os.system('del ' + tempsticker)
        reply(msg, None, replymsg)