get_sticker_owner.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from pyrogram import Client, filters
  4. from pyrogram.raw import types, functions
  5. from pyrogram.enums import ParseMode, MessageEntityType
  6. api_id =
  7. api_hash = ""
  8. app = Client("my_bot", api_id=api_id, api_hash=api_hash)
  9. # message(sticker) | sticker set short name
  10. def get_owner_id(data):
  11. try:
  12. short_name = data.reply_to_message.sticker.set_name
  13. except: # noqa: E722
  14. if not isinstance(data, str):
  15. return None
  16. short_name = data
  17. sticker_set = app.invoke(
  18. functions.messages.GetStickerSet(
  19. stickerset=types.InputStickerSetShortName(short_name=short_name),
  20. hash=0
  21. )
  22. )
  23. owner_id = sticker_set.set.id >> 32
  24. return owner_id
  25. def get_inline_bot_data(id):
  26. data = {"id": id, "name": None, "username": None}
  27. inline_search = app.get_inline_bot_results("tgdb_bot", str(id))
  28. if "\n" not in inline_search.results[0].send_message.message:
  29. return None
  30. temp = inline_search.results[0].send_message.message.split("\n\n")[0]
  31. temp = temp.split("\n")[2:]
  32. def split(x): return x.split(": ", 1)[1]
  33. data["name"] = split(temp[0])
  34. data["username"] = split(temp[1]) if len(temp) > 1 else None
  35. return data
  36. def get_pyrogram_user_data(id):
  37. data = {"id": id, "name": None, "username": None}
  38. try:
  39. res = app.get_users(id)
  40. last = res.last_name if res.get('last_name') else ''
  41. data["name"] = f"{res.first_name} {last}"
  42. data["username"] = f"@{res.username}" if res.get("username") else None
  43. return data
  44. except: # noqa: E722
  45. return None
  46. def get_user_data(id):
  47. data = {"id": id, "name": None, "username": None}
  48. if data := get_inline_bot_data(id):
  49. return data
  50. if data := get_pyrogram_user_data(id):
  51. return data
  52. return data
  53. def get_emoji_set_names(message):
  54. custom_emojis = []
  55. for entity in message.reply_to_message.caption_entities:
  56. if entity.type == MessageEntityType.CUSTOM_EMOJI:
  57. custom_emojis.append(entity.custom_emoji_id)
  58. custom_emojis = app.get_custom_emoji_stickers(set(custom_emojis))
  59. set_names = [emoji.set_name for emoji in custom_emojis]
  60. return tuple(set(set_names))
  61. def get_user_data_text(message):
  62. if owner_id := get_owner_id(message):
  63. data = get_user_data(owner_id)
  64. text = f"ID: `{owner_id}`\n"
  65. if name := data["name"]:
  66. text += f"Name: `{name}`\n"
  67. if username := data["username"]:
  68. text += f"Username: {username}\n"
  69. return text
  70. return ""
  71. @app.on_message(filters.command(["owner",],prefixes=".") & filters.me)
  72. def get_owner_stickers(_, message):
  73. text = ""
  74. try:
  75. if t := get_user_data_text(message):
  76. name = message.reply_to_message.sticker.set_name
  77. text += f"https://t.me/addstickers/{name}\n"
  78. text += t
  79. else:
  80. set_names = get_emoji_set_names(message)
  81. for short_name in set_names:
  82. text += f"https://t.me/addemoji/{short_name} \n"
  83. text += get_user_data_text(short_name)
  84. text += "\n\n"
  85. except: # noqa: E722
  86. text = "no sticker or custom emoji here"
  87. app.edit_message_text(message.chat.id, message.id, text,
  88. parse_mode=ParseMode.MARKDOWN,
  89. disable_web_page_preview=True)
  90. app.run()