presets.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. # ©️ Dan Gazizullin, 2021-2023
  2. # This file is a part of Hikka Userbot
  3. # 🌐 https://github.com/hikariatama/Hikka
  4. # You can redistribute it and/or modify it under the terms of the GNU AGPLv3
  5. # 🔑 https://www.gnu.org/licenses/agpl-3.0.html
  6. import asyncio
  7. import logging
  8. from .. import loader, utils
  9. from ..inline.types import BotInlineMessage, InlineCall
  10. logger = logging.getLogger(__name__)
  11. PRESETS = {
  12. "fun": [
  13. "https://mods.hikariatama.ru/aniquotes.py",
  14. "https://mods.hikariatama.ru/artai.py",
  15. "https://mods.hikariatama.ru/inline_ghoul.py",
  16. "https://mods.hikariatama.ru/lovemagic.py",
  17. "https://mods.hikariatama.ru/mindgame.py",
  18. "https://mods.hikariatama.ru/moonlove.py",
  19. "https://mods.hikariatama.ru/neko.py",
  20. "https://mods.hikariatama.ru/purr.py",
  21. "https://mods.hikariatama.ru/rpmod.py",
  22. "https://mods.hikariatama.ru/scrolller.py",
  23. "https://mods.hikariatama.ru/tictactoe.py",
  24. "https://mods.hikariatama.ru/trashguy.py",
  25. "https://mods.hikariatama.ru/truth_or_dare.py",
  26. "https://mods.hikariatama.ru/sticks.py",
  27. "https://mods.hikariatama.ru/premium_sticks.py",
  28. "https://heta.hikariatama.ru/MoriSummerz/ftg-mods/magictext.py",
  29. "https://heta.hikariatama.ru/HitaloSama/FTG-modules-repo/quotes.py",
  30. "https://heta.hikariatama.ru/HitaloSama/FTG-modules-repo/spam.py",
  31. "https://heta.hikariatama.ru/SkillsAngels/Modules/IrisLab.py",
  32. "https://heta.hikariatama.ru/Fl1yd/FTG-Modules/arts.py",
  33. "https://heta.hikariatama.ru/SkillsAngels/Modules/Complements.py",
  34. "https://heta.hikariatama.ru/Den4ikSuperOstryyPer4ik/Astro-modules/Compliments.py",
  35. "https://heta.hikariatama.ru/vsecoder/hikka_modules/mazemod.py",
  36. ],
  37. "chat": [
  38. "https://mods.hikariatama.ru/activists.py",
  39. "https://mods.hikariatama.ru/banstickers.py",
  40. "https://mods.hikariatama.ru/hikarichat.py",
  41. "https://mods.hikariatama.ru/inactive.py",
  42. "https://mods.hikariatama.ru/keyword.py",
  43. "https://mods.hikariatama.ru/tagall.py",
  44. "https://mods.hikariatama.ru/voicechat.py",
  45. "https://mods.hikariatama.ru/vtt.py",
  46. "https://heta.hikariatama.ru/SekaiYoneya/Friendly-telegram/BanMedia.py",
  47. "https://heta.hikariatama.ru/iamnalinor/FTG-modules/swmute.py",
  48. "https://heta.hikariatama.ru/GeekTG/FTG-Modules/filter.py",
  49. ],
  50. "service": [
  51. "https://mods.hikariatama.ru/account_switcher.py",
  52. "https://mods.hikariatama.ru/surl.py",
  53. "https://mods.hikariatama.ru/httpsc.py",
  54. "https://mods.hikariatama.ru/img2pdf.py",
  55. "https://mods.hikariatama.ru/latex.py",
  56. "https://mods.hikariatama.ru/pollplot.py",
  57. "https://mods.hikariatama.ru/sticks.py",
  58. "https://mods.hikariatama.ru/temp_chat.py",
  59. "https://mods.hikariatama.ru/vtt.py",
  60. "https://heta.hikariatama.ru/vsecoder/hikka_modules/accounttime.py",
  61. "https://heta.hikariatama.ru/vsecoder/hikka_modules/searx.py",
  62. "https://heta.hikariatama.ru/iamnalinor/FTG-modules/swmute.py",
  63. ],
  64. "downloaders": [
  65. "https://mods.hikariatama.ru/musicdl.py",
  66. "https://mods.hikariatama.ru/uploader.py",
  67. "https://mods.hikariatama.ru/porn.py",
  68. "https://mods.hikariatama.ru/web2file.py",
  69. "https://heta.hikariatama.ru/AmoreForever/amoremods/instsave.py",
  70. "https://heta.hikariatama.ru/CakesTwix/Hikka-Modules/tikcock.py",
  71. "https://heta.hikariatama.ru/CakesTwix/Hikka-Modules/InlineYouTube.py",
  72. "https://heta.hikariatama.ru/CakesTwix/Hikka-Modules/InlineSpotifyDownloader.py",
  73. "https://heta.hikariatama.ru/GeekTG/FTG-Modules/downloader.py",
  74. "https://heta.hikariatama.ru/Den4ikSuperOstryyPer4ik/Astro-modules/dl_yt_previews.py",
  75. ],
  76. }
  77. @loader.tds
  78. class Presets(loader.Module):
  79. """Suggests new Hikka users a packs of modules to load"""
  80. strings = {"name": "Presets"}
  81. async def client_ready(self):
  82. self._markup = utils.chunks(
  83. [
  84. {
  85. "text": self.strings(f"_{preset}_title"),
  86. "callback": self._preset,
  87. "args": (preset,),
  88. }
  89. for preset in PRESETS
  90. ],
  91. 1,
  92. )
  93. if self.get("sent"):
  94. return
  95. self.set("sent", True)
  96. await self._menu()
  97. async def _menu(self):
  98. await self.inline.bot.send_message(
  99. self._client.tg_id,
  100. self.strings("welcome"),
  101. reply_markup=self.inline.generate_markup(self._markup),
  102. )
  103. async def _back(self, call: InlineCall):
  104. await call.edit(self.strings("welcome"), reply_markup=self._markup)
  105. async def _install(self, call: InlineCall, preset: str):
  106. await call.delete()
  107. m = await self._client.send_message(
  108. self.inline.bot_id,
  109. self.strings("installing").format(preset),
  110. )
  111. for i, module in enumerate(PRESETS[preset]):
  112. await m.edit(
  113. self.strings("installing_module").format(
  114. preset,
  115. i,
  116. len(PRESETS[preset]),
  117. module,
  118. )
  119. )
  120. try:
  121. await self.lookup("loader").download_and_install(module, None)
  122. except Exception:
  123. logger.exception("Failed to install module %s", module)
  124. await asyncio.sleep(1)
  125. if self.lookup("loader").fully_loaded:
  126. self.lookup("loader").update_modules_in_db()
  127. await m.edit(self.strings("installed").format(preset))
  128. await self._menu()
  129. def _is_installed(self, link: str) -> bool:
  130. return any(
  131. link.strip().lower() == installed.strip().lower()
  132. for installed in self.lookup("loader").get("loaded_modules", {}).values()
  133. )
  134. async def _preset(self, call: InlineCall, preset: str):
  135. await call.edit(
  136. self.strings("preset").format(
  137. self.strings(f"_{preset}_title"),
  138. self.strings(f"_{preset}_desc"),
  139. "\n".join(
  140. map(
  141. lambda x: x[0],
  142. sorted(
  143. [
  144. (
  145. "{} <b>{}</b>".format(
  146. (
  147. self.strings("already_installed")
  148. if self._is_installed(link)
  149. else "▫️"
  150. ),
  151. link.rsplit("/", maxsplit=1)[1].split(".")[0],
  152. ),
  153. int(self._is_installed(link)),
  154. )
  155. for link in PRESETS[preset]
  156. ],
  157. key=lambda x: x[1],
  158. reverse=True,
  159. ),
  160. )
  161. ),
  162. ),
  163. reply_markup=[
  164. {"text": self.strings("back"), "callback": self._back},
  165. {
  166. "text": self.strings("install"),
  167. "callback": self._install,
  168. "args": (preset,),
  169. },
  170. ],
  171. )
  172. async def aiogram_watcher(self, message: BotInlineMessage):
  173. if message.text != "/presets" or message.from_user.id != self._client.tg_id:
  174. return
  175. await self._menu()