def push_instruction_and_record_prefix(instructions, op, op_args, path, dir_index, random, subspace): if not op.endswith('_DATABASE'): instructions.push_args(1, *test_util.with_length(path)) instructions.append('DIRECTORY_EXISTS') # This op must leave the stack in the state it is in at this point, with the exception # that it may leave an error on the stack instructions.push_args(*op_args) instructions.append(op) if not op.endswith('_DATABASE'): instructions.push_args(dir_index) instructions.append('DIRECTORY_CHANGE') instructions.push_args(1, b'', random.random_string(16), b'') instructions.append('DIRECTORY_PACK_KEY') test_util.to_front( instructions, 3) # move the existence result up to the front of the stack t = util.subspace_to_tuple(subspace) instructions.push_args(len(t) + 3, *t) instructions.append( 'TUPLE_PACK' ) # subspace[<exists>][<packed_key>][random.random_string(16)] = b'' instructions.append('SET') instructions.push_args(DEFAULT_DIRECTORY_INDEX) instructions.append('DIRECTORY_CHANGE')
def create_default_directory_subspace(instructions, path, random): test_util.blocking_commit(instructions) instructions.push_args(3) instructions.append('DIRECTORY_CHANGE') prefix = random.random_string(16) instructions.push_args(1, path, '', '%s-%s' % (DEFAULT_DIRECTORY_PREFIX, prefix)) instructions.append('DIRECTORY_CREATE_DATABASE') instructions.push_args(DEFAULT_DIRECTORY_INDEX) instructions.append('DIRECTORY_CHANGE')
def refine3(t: type, f: Callable[[T], bool]) -> type: def init(s, x:t) -> None: if not (isinstance(x, t) or f(x)): fail("Type error. You tried to use " + str(x) + " with subtype of " + str(t) + ".") else: t(x) # We use a random string as class name here. The result of refine3 has to # get assigend to a type alias, which can be used as class name. u_rand = ''.join(random_string(ascii_uppercase + ascii_lowercase, k=15)) cl = type(u_rand, (t,), {'__init__': init}) return cl
async def kang_cmd(ult): sender = await ult.get_sender() if not isinstance(sender, User): return if not ult.is_reply: return await ult.eor("`Reply to a sticker/photo..`", time=5) reply = await ult.get_reply_message() if sender.username: pre = sender.username[:4] else: pre = random.random_string(length=3) animated, dl = None, None try: emoji = ult.text.split(maxsplit=1)[1] except IndexError: emoji = None if reply.sticker: file = get_input_document(reply.sticker) emoji = emoji or reply.file.emoji if reply.file.name.endswith(".tgs"): animated = True dl = await reply.download_media() elif reply.photo: dl = await reply.download_media() name = "sticker.webp" image = resize_photo(dl) image.save(name, "WEBP") elif reply.text: dl = await create_quotly(reply) else: return await ult.eor("`Reply to sticker or text to add it in your pack...`") if not emoji: emoji = "🏵" if dl: upl = await ult.client.upload_file(dl) file = get_input_document( await ult.client(UploadMediaRequest(InputPeerSelf(), upl)) ) get_ = udB.get_key("STICKERS") or {} type_ = "static" if not animated else "anim" if not get_.get(ult.sender_id) or not get_.get(ult.sender_id, {}).get(type_): sn = f"{pre}_{ult.sender_id}" title = f"{get_display_name(sender)}'s Kang Pack" if animated: type_ = "anim" sn += "_anim" title += " (Animated)" sn += f"_by_{asst.me.username}" try: await asst(GetSticker(InputStickerSetShortName(sn), hash=0)) sn = sn.replace(str(ult.sender_id), f"{ult.sender_id}_{ult.id}") except StickersetInvalidError: pass try: pack = await ult.client( CreateStickerSetRequest( user_id=sender.id, title=title, short_name=sn, stickers=[SetItem(file, emoji=emoji)], animated=animated, ) ) except Exception as er: return await ult.eor(str(er)) sn = pack.set.short_name if not get_.get(ult.sender_id): get_.update({ult.sender_id: {type_: [sn]}}) else: get_[ult.sender_id].update({type_: [sn]}) udB.set_key("STICKERS", get_) return await ult.reply( f"**Kanged Successfully!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})" ) name = get_[ult.sender_id][type_][-1] try: await asst(GetSticker(InputStickerSetShortName(name), hash=0)) except StickersetInvalidError: get_[ult.sender_id][type_].remove(name) try: await asst( AddSticker(InputStickerSetShortName(name), SetItem(file, emoji=emoji)) ) except (errors.StickerpackStickersTooMuchError, errors.StickersTooMuchError): sn = f"{pre}{ult.sender_id}_{ult.id}" title = f"{get_display_name(sender)}'s Kang Pack" if animated: sn += "_anim" title += " (Animated)" sn += f"_by_{asst.me.username}" try: pack = await ult.client( CreateStickerSetRequest( user_id=sender.id, title=title, short_name=sn, stickers=[SetItem(file, emoji=emoji)], animated=animated, ) ) except Exception as er: return await ult.eor(str(er)) get_[ult.sender_id][type_].append(pack.set.short_name) udB.set_key("STICKERS", get_) return await ult.reply( f"**Created New Kang Pack!\nEmoji :** {emoji}\n**Link :** [Click Here](https://t.me/addstickers/{sn})" ) except Exception as er: LOGS.exception(er) return await ult.reply(str(er)) await ult.reply( f"Sticker Added to Pack Successfully\n**Link :** [Click Here](https://t.me/addstickers/{name})" )