quickstart.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 logging
  7. import os
  8. from random import choice
  9. from .. import loader, translations, utils
  10. from ..inline.types import BotInlineCall
  11. logger = logging.getLogger(__name__)
  12. imgs = [
  13. "https://i.gifer.com/GmUB.gif",
  14. "https://i.gifer.com/Afdn.gif",
  15. "https://i.gifer.com/3uvT.gif",
  16. "https://i.gifer.com/2qQQ.gif",
  17. "https://i.gifer.com/Lym6.gif",
  18. "https://i.gifer.com/IjT4.gif",
  19. "https://i.gifer.com/A9H.gif",
  20. ]
  21. @loader.tds
  22. class Quickstart(loader.Module):
  23. """Notifies user about userbot installation"""
  24. async def client_ready(self):
  25. self.mark = lambda: [
  26. [
  27. {
  28. "text": self.strings("btn_support"),
  29. "url": "https://t.me/hikka_talks",
  30. }
  31. ],
  32. ] + utils.chunks(
  33. [
  34. {
  35. "text": self.strings.get("language", lang),
  36. "data": f"hikka/lang/{lang}",
  37. }
  38. for lang in translations.SUPPORTED_LANGUAGES
  39. ],
  40. 3,
  41. )
  42. self.text = (
  43. lambda: self.strings("base")
  44. + (
  45. "\n"
  46. + (
  47. self.strings("railway")
  48. if "RAILWAY" in os.environ
  49. else (self.strings("lavhost") if "LAVHOST" in os.environ else "")
  50. )
  51. ).rstrip()
  52. )
  53. if self.get("no_msg"):
  54. return
  55. await self.inline.bot.send_animation(self._client.tg_id, animation=choice(imgs))
  56. await self.inline.bot.send_message(
  57. self._client.tg_id,
  58. self.text(),
  59. reply_markup=self.inline.generate_markup(self.mark()),
  60. disable_web_page_preview=True,
  61. )
  62. self.set("no_msg", True)
  63. @loader.callback_handler()
  64. async def lang(self, call: BotInlineCall):
  65. if not call.data.startswith("hikka/lang/"):
  66. return
  67. lang = call.data.split("/")[2]
  68. self._db.set(translations.__name__, "lang", lang)
  69. await self.allmodules.reload_translations()
  70. await call.answer(self.strings("language_saved"))
  71. await call.edit(text=self.text(), reply_markup=self.mark())