Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def get_sticker_set_by_name(
- client: Client, name: str
- ) -> raw.base.messages.StickerSet:
- try:
- return await client.invoke(
- raw.functions.messages.GetStickerSet(
- stickerset=raw.types.InputStickerSetShortName(short_name=name),
- hash=0,
- )
- )
- except errors.exceptions.not_acceptable_406.StickersetInvalid:
- return None
- async def create_sticker_set(
- client: Client,
- owner: int,
- title: str,
- short_name: str,
- stickers: List[raw.base.InputStickerSetItem],
- animated:bool=False,
- video:bool=False
- ) -> raw.base.messages.StickerSet:
- return await client.invoke(
- raw.functions.stickers.CreateStickerSet(
- user_id=await client.resolve_peer(owner),
- title=title,
- short_name=short_name,
- stickers=stickers,
- animated=animated,
- videos=video
- )
- )
- async def add_sticker_to_set(
- client: Client,
- stickerset: raw.base.messages.StickerSet,
- sticker: raw.base.InputStickerSetItem,
- ) -> raw.base.messages.StickerSet:
- return await client.invoke(
- raw.functions.stickers.AddStickerToSet(
- stickerset=raw.types.InputStickerSetShortName(
- short_name=stickerset.set.short_name
- ),
- sticker=sticker,
- )
- )
- async def create_sticker(
- sticker: raw.base.InputDocument, emoji: str
- ) -> raw.base.InputStickerSetItem:
- return raw.types.InputStickerSetItem(document=sticker, emoji=emoji)
- async def upload_document(
- client: Client, file_path: str, chat_id: int
- ) -> raw.base.InputDocument:
- media = await client.invoke(
- raw.functions.messages.UploadMedia(
- peer=await client.resolve_peer(chat_id),
- media=raw.types.InputMediaUploadedDocument(
- mime_type=client.guess_mime_type(file_path) or "application/zip",
- file=await client.save_file(file_path),
- attributes=[
- raw.types.DocumentAttributeFilename(
- file_name=os.path.basename(file_path)
- )
- ],
- ),
- )
- )
- return raw.types.InputDocument(
- id=media.document.id,
- access_hash=media.document.access_hash,
- file_reference=media.document.file_reference,
- )
- async def get_document_from_file_id(
- file_id: str,
- ) -> raw.base.InputDocument:
- decoded = FileId.decode(file_id)
- return raw.types.InputDocument(
- id=decoded.media_id,
- access_hash=decoded.access_hash,
- file_reference=decoded.file_reference,
- )
- # ==========================================
- @Gojo.on_message(command(["kang", "steal"]))
- async def kang(c:Gojo, m: Message):
- if not m.reply_to_message:
- return await m.reply_text("Reply to a sticker or image to kang it.")
- elif not (m.reply_to_message.sticker or m.reply_to_message.photo or (m.reply_to_message.document and m.reply_to_message.document.mime_type.split("/")[0]=="image")):
- return await m.reply_text("Reply to a sticker or image to kang it.")
- if not m.from_user:
- return await m.reply_text("You are anon admin, kang stickers in my pm.")
- msg = await m.reply_text("Kanging Sticker..")
- # Find the proper emoji
- args = m.text.split()
- if len(args) > 1:
- sticker_emoji = str(args[1])
- else:
- edit_ = await msg.edit_text("No emoji provided choosing a random emoji")
- ran = ["๐คฃ", "๐", "๐", "๐", "๐ฅ", "๐", "๐", "๐", "๐", "๐ฑ", "โบ๏ธ", "๐", "๐", "๐คง", "๐", "๐ฌ", "๐คฉ", "๐", "๐", "๐ฅน", "๐ฅบ", "๐ซฅ", "๐", "๐ซก", "๐ซ ", "๐คซ", "๐", "๐ฅต", "๐ฅถ", "๐ค", "๐ก", "๐คฌ", "๐คฏ", "๐ฅด", "๐คข", "๐คฎ", "๐", "๐ฟ", "๐ฉ", "๐คก", "๐ซถ", "๐", "๐", "โ", "๐", "๐ซฐ", "๐ค", "๐", "๐", "๐", "๐บ", "๐ฉโโค๏ธโ๐โ๐ฉ", "๐ฉโโค๏ธโ๐โ๐จ","๐จโโค๏ธโ๐จ", "๐", "๐ฉโโค๏ธโ๐ฉ", "๐ฉโโค๏ธโ๐จ", "๐", "๐จโโค๏ธโ๐โ๐จ", "๐ช", "๐ด", "๐ญ", "๐ฅธ", "๐ค", "๐ซค", "๐ฎ", "๐ง", "๐ฒ", "๐ฅฑ", "๐", "๐ฟ", "๐ค", "๐พ", "๐", "๐ฅด", "๐ฅฐ", "๐", "๐คฃ" ,"๐", "๐", "๐"]
- sticker_emoji = choice(ran)
- await edit_.edit_text(f"Makeing a sticker with {sticker_emoji} emoji")
- # Get the corresponding fileid, resize the file if necessary
- try:
- if m.reply_to_message.photo or (m.reply_to_message.document and m.reply_to_message.document.mime_type.split("/")[0]=="image"):
- sizee = (await get_file_size(m.reply_to_message)).split()
- if (sizee[1] == "mb" and sizee > 10) or sizee[1] == "gb":
- await m.reply_text("File size is too big")
- return
- path = await m.reply_to_message.download()
- try:
- path = await resize_file_to_sticker_size(path)
- except OSError as e:
- await m.reply_text(f"Error\n{e}")
- LOGGER.error(e)
- LOGGER.error(format_exc)
- os.remove(path)
- return
- except Exception as e:
- await m.reply_text(f"Got an error:\n{e}")
- LOGGER.error(e)
- LOGGER.error(format_exc())
- return
- try:
- if not m.reply_to_message.sticker:
- sticker = await create_sticker(
- await upload_document(
- c, path, m.chat.id
- ),
- sticker_emoji
- )
- await edit_.delete()
- os.remove(path)
- elif m.reply_to_message.sticker:
- sticker = await create_sticker(
- await get_document_from_file_id(
- m.reply_to_message.sticker.file_id
- ),
- sticker_emoji
- )
- except ShortnameOccupyFailed:
- await m.reply_text("Change Your Name Or Username")
- return
- except Exception as e:
- await m.reply_text(str(e))
- e = format_exc()
- LOGGER.error(e)
- LOGGER.error(format_exc())
- # Find an available pack & add the sticker to the pack; create a new pack if needed
- # Would be a good idea to cache the number instead of searching it every single time...
- kang_lim = 120
- st_in = m.reply_to_message.sticker
- st_type = "norm"
- is_anim = is_vid = False
- if st_in:
- if st_in.is_animated:
- st_type = "ani"
- kang_lim = 50
- is_anim = True
- elif st_in.is_video:
- st_type = "vid"
- kang_lim = 50
- is_vid = True
- packnum = 0
- limit = 0
- volume = 0
- packname_found = False
- try:
- while not packname_found:
- packname = f"CE{str(m.from_user.id)}{st_type}{packnum}_by_{Config.BOT_USERNAME}"
- kangpack = f"{('@'+m.from_user.username) if m.from_user.username else m.from_user.first_name[:10]} {st_type} {('vOl '+str(volume)) if volume else ''} by @{Config.BOT_USERNAME}"
- if limit >= 50: # To prevent this loop from running forever
- await msg.delete()
- await m.reply_text("Failed to kang\nMay be you have made more than 50 sticker packs with me try deleting some")
- return
- sticker_set = await get_sticker_set_by_name(c,packname)
- if not sticker_set:
- sticker_set = await create_sticker_set(
- client=c,
- owner=m.from_user.id,
- title=kangpack,
- short_name=packname,
- stickers=[sticker],
- animated=is_anim,
- video=is_vid
- )
- elif sticker_set.set.count >= kang_lim:
- packnum += 1
- limit += 1
- volume += 1
- continue
- else:
- try:
- await add_sticker_to_set(c,sticker_set,sticker)
- except StickerEmojiInvalid:
- return await msg.edit("[ERROR]: INVALID_EMOJI_IN_ARGUMENT")
- limit += 1
- packname_found = True
- kb = IKM(
- [
- [
- IKB("โ Add Pack โ",url=f"t.me/addstickers/{packname}")
- ]
- ]
- )
- await msg.edit_text(
- f"Kanged the sticker\nPack name: {kangpack}\nEmoji: {sticker_emoji}",
- reply_markup=kb
- )
- except (PeerIdInvalid, UserIsBlocked):
- keyboard = IKM(
- [[IKB("Start me first", url=f"t.me/{Config.BOT_USERNAME}")]]
- )
- await msg.edit_text(
- "You Need To Start A Private Chat With Me.",
- reply_markup=keyboard,
- )
- except StickerPngNopng:
- await msg.delete()
- await m.reply_text(
- "Stickers must be png files but the provided image was not a png"
- )
- except StickerPngDimensions:
- await msg.delete()
- await m.reply_text("The sticker png dimensions are invalid.")
- except StickerTgsNotgs:
- await msg.delete()
- await m.reply_text("Sticker must be tgs file but the provided file was not tgs")
- except StickerVideoNowebm:
- await msg.delete()
- await m.reply_text("Sticker must be webm file but the provided file was not webm")
- except Exception as e:
- await msg.delete()
- await m.reply_text(f"Error occured\n{e}")
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement