hikka_info.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # █ █ ▀ █▄▀ ▄▀█ █▀█ ▀
  2. # █▀█ █ █ █ █▀█ █▀▄ █
  3. # © Copyright 2022
  4. # https://t.me/hikariatama
  5. #
  6. # 🔒 Licensed under the GNU AGPLv3
  7. # 🌐 https://www.gnu.org/licenses/agpl-3.0.html
  8. # scope: inline
  9. import logging
  10. import git
  11. from telethon.tl.types import Message
  12. from telethon.utils import get_display_name
  13. from .. import loader, main, utils
  14. from ..inline.types import InlineQuery
  15. logger = logging.getLogger(__name__)
  16. @loader.tds
  17. class HikkaInfoMod(loader.Module):
  18. """Show userbot info"""
  19. strings = {
  20. "name": "HikkaInfo",
  21. "owner": "Owner",
  22. "version": "Version",
  23. "build": "Build",
  24. "prefix": "Prefix",
  25. "send_info": "Send userbot info",
  26. "description": "ℹ This will not compromise any sensitive info",
  27. "up-to-date": "😌 Up-to-date",
  28. "update_required": "😕 Update required </b><code>.update</code><b>",
  29. "_cfg_cst_msg": (
  30. "Custom message for info. May contain {me}, {version}, {build}, {prefix},"
  31. " {platform}, {upd}, {uptime} keywords"
  32. ),
  33. "_cfg_cst_btn": "Custom button for info. Leave empty to remove button",
  34. "_cfg_banner": "URL to image banner",
  35. }
  36. strings_ru = {
  37. "owner": "Владелец",
  38. "version": "Версия",
  39. "build": "Сборка",
  40. "prefix": "Префикс",
  41. "send_info": "Отправить информацию о юзерботе",
  42. "description": "ℹ Это не раскроет никакой личной информации",
  43. "_ihandle_doc_info": "Отправить информацию о юзерботе",
  44. "up-to-date": "😌 Актуальная версия",
  45. "update_required": "😕 Требуется обновление </b><code>.update</code><b>",
  46. "_cfg_cst_msg": (
  47. "Кастомный текст сообщения в info. Может содержать ключевые слова {me},"
  48. " {version}, {build}, {prefix}, {platform}, {upd}, {uptime}"
  49. ),
  50. "_cfg_cst_btn": (
  51. "Кастомная кнопка в сообщении в info. Оставь пустым, чтобы убрать кнопку"
  52. ),
  53. "_cfg_banner": "Ссылка на баннер-картинку",
  54. }
  55. def __init__(self):
  56. self.config = loader.ModuleConfig(
  57. loader.ConfigValue(
  58. "custom_message",
  59. doc=lambda: self.strings("_cfg_cst_msg"),
  60. ),
  61. loader.ConfigValue(
  62. "custom_button",
  63. ["🌘 Support chat", "https://t.me/hikka_talks"],
  64. lambda: self.strings("_cfg_cst_btn"),
  65. validator=loader.validators.Union(
  66. loader.validators.Series(fixed_len=2),
  67. loader.validators.NoneType(),
  68. ),
  69. ),
  70. loader.ConfigValue(
  71. "banner_url",
  72. "https://github.com/hikariatama/assets/raw/master/hikka_banner.png",
  73. lambda: self.strings("_cfg_banner"),
  74. validator=loader.validators.Link(),
  75. ),
  76. )
  77. async def client_ready(self, client, _):
  78. self._me = await client.get_me()
  79. def _render_info(self) -> str:
  80. ver = utils.get_git_hash() or "Unknown"
  81. try:
  82. repo = git.Repo(search_parent_directories=True)
  83. diff = repo.git.log(["HEAD..origin/master", "--oneline"])
  84. upd = (
  85. self.strings("update_required") if diff else self.strings("up-to-date")
  86. )
  87. except Exception:
  88. upd = ""
  89. me = (
  90. "<b><a"
  91. f' href="tg://user?id={self._me.id}">{utils.escape_html(get_display_name(self._me))}</a></b>'
  92. )
  93. version = f'<i>{".".join(list(map(str, list(main.__version__))))}</i>'
  94. build = (
  95. f'<a href="https://github.com/hikariatama/Hikka/commit/{ver}">#{ver[:8]}</a>'
  96. )
  97. prefix = f"«<code>{utils.escape_html(self.get_prefix())}</code>»"
  98. platform = utils.get_named_platform()
  99. return (
  100. (
  101. "<b>🌘 Hikka</b>\n"
  102. if "hikka" not in self.config["custom_message"].lower()
  103. else ""
  104. )
  105. + self.config["custom_message"].format(
  106. me=me,
  107. version=version,
  108. build=build,
  109. prefix=prefix,
  110. platform=platform,
  111. upd=upd,
  112. uptime=utils.formatted_uptime(),
  113. )
  114. if self.config["custom_message"] and self.config["custom_message"] != "no"
  115. else (
  116. "<b>🌘 Hikka</b>\n"
  117. f'<b>🤴 {self.strings("owner")}: </b>{me}\n\n'
  118. f"<b>🔮 {self.strings('version')}: </b>{version} {build}\n"
  119. f"<b>{upd}</b>\n\n"
  120. f"<b>📼 {self.strings('prefix')}: </b>{prefix}\n"
  121. f"<b>{platform}</b>\n"
  122. )
  123. )
  124. def _get_mark(self):
  125. return (
  126. {
  127. "text": self.config["custom_button"][0],
  128. "url": self.config["custom_button"][1],
  129. }
  130. if self.config["custom_button"]
  131. else None
  132. )
  133. @loader.inline_everyone
  134. async def info_inline_handler(self, query: InlineQuery) -> dict:
  135. """Send userbot info"""
  136. return {
  137. "title": self.strings("send_info"),
  138. "description": self.strings("description"),
  139. "message": self._render_info(),
  140. "thumb": (
  141. "https://github.com/hikariatama/Hikka/raw/master/assets/hikka_pfp.png"
  142. ),
  143. "reply_markup": self._get_mark(),
  144. }
  145. @loader.unrestricted
  146. async def infocmd(self, message: Message):
  147. """Send userbot info"""
  148. await self.inline.form(
  149. message=message,
  150. text=self._render_info(),
  151. reply_markup=self._get_mark(),
  152. **(
  153. {"photo": self.config["banner_url"]}
  154. if self.config["banner_url"]
  155. else {}
  156. ),
  157. )
  158. @loader.unrestricted
  159. async def hikkainfocmd(self, message: Message):
  160. """[en/ru - default en] - Send info aka 'What is Hikka?'"""
  161. args = utils.get_args_raw(message)
  162. args = args if args in {"en", "ru"} else "en"
  163. await utils.answer(
  164. message,
  165. "🌘 <b>Hikka</b>\n\n"
  166. "Brand new userbot for Telegram with a lot of features, "
  167. "aka InlineGalleries, forms etc. Userbot - software, running "
  168. "on your Telegram account. If you write a command to any chat, it will "
  169. "get executed right there. Check out live examples at "
  170. '<a href="https://github.com/hikariatama/Hikka">GitHub</a>'
  171. if args == "en"
  172. else (
  173. "🌘 <b>Hikka</b>\n\nНовый юзербот для Telegram с огромным количеством"
  174. " функций, из которых: Инлайн галереи, формы и другое. Юзербот -"
  175. " программа, которая запускается на твоем Telegram-аккаунте. Когда ты"
  176. " пишешь команду в любом чате, она сразу же выполняется. Обрати"
  177. " внимание на живые примеры на <a"
  178. ' href="https://github.com/hikariatama/Hikka">GitHub</a>'
  179. ),
  180. )