__init__.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # flake8: noqa F405
  2. """
  3. MIT License
  4. Copyright (c) 2021 TheHamkerCat
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. SOFTWARE.
  20. """
  21. import asyncio
  22. import time
  23. from os import path
  24. from aiohttp import ClientSession
  25. from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
  26. from pyrogram import Client
  27. from Python_ARQ import ARQ
  28. from telegraph import Telegraph
  29. print("[INFO]: INITIALIZING")
  30. is_config = path.exists("config.py")
  31. if is_config:
  32. from config import *
  33. else:
  34. from sample_config import *
  35. USERBOT_PREFIX = USERBOT_PREFIX
  36. GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
  37. SUDOERS = SUDO_USERS_ID
  38. FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
  39. WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
  40. LOG_GROUP_ID = LOG_GROUP_ID
  41. MESSAGE_DUMP_CHAT = MESSAGE_DUMP_CHAT
  42. MOD_LOAD = []
  43. MOD_NOLOAD = []
  44. bot_start_time = time.time()
  45. # MongoDB client
  46. print("[INFO]: INITIALIZING DATABASE")
  47. mongo_client = MongoClient(MONGO_DB_URI)
  48. db = mongo_client.wbb
  49. async def load_sudoers():
  50. global SUDOERS
  51. print("[INFO]: LOADING SUDOERS")
  52. sudoersdb = db.sudoers
  53. sudoers = await sudoersdb.find_one({"sudo": "sudo"})
  54. sudoers = [] if not sudoers else sudoers["sudoers"]
  55. for user_id in SUDOERS:
  56. if user_id not in sudoers:
  57. sudoers.append(user_id)
  58. await sudoersdb.update_one(
  59. {"sudo": "sudo"}, {"$set": {"sudoers": sudoers}}, upsert=True
  60. )
  61. SUDOERS = (SUDOERS + sudoers) if sudoers else SUDOERS
  62. loop = asyncio.get_event_loop()
  63. loop.run_until_complete(load_sudoers())
  64. if not HEROKU:
  65. print("[INFO]: INITIALIZING USERBOT CLIENT")
  66. app2 = Client(
  67. "userbot", phone_number=PHONE_NUMBER, api_id=API_ID, api_hash=API_HASH
  68. )
  69. else:
  70. print("[INFO]: INITIALIZING USERBOT CLIENT")
  71. app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
  72. # Bot client
  73. print("[INFO]: INITIALIZING BOT CLIENT")
  74. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  75. # ARQ client
  76. print("[INFO]: INITIALIZING ARQ")
  77. arq = ARQ(ARQ_API_URL, ARQ_API_KEY)
  78. # Telegraph client
  79. print("[INFO]: INITIALIZING TELEGRAPH")
  80. telegraph = Telegraph()
  81. telegraph.create_account(short_name="wbb")
  82. # Aiohttp Client
  83. print("[INFO]: INITIALZING AIOHTTP SESSION")
  84. aiohttpsession = ClientSession()
  85. BOT_ID = 0
  86. BOT_NAME = ""
  87. BOT_USERNAME = ""
  88. BOT_MENTION = ""
  89. BOT_DC_ID = 0
  90. USERBOT_ID = 0
  91. USERBOT_NAME = ""
  92. USERBOT_USERNAME = ""
  93. USERBOT_DC_ID = 0
  94. USERBOT_MENTION = ""
  95. def get_info(app, app2):
  96. global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID, BOT_MENTION
  97. global USERBOT_ID, USERBOT_NAME, USERBOT_USERNAME, USERBOT_DC_ID, USERBOT_MENTION
  98. getme = app.get_me()
  99. getme2 = app2.get_me()
  100. BOT_ID = getme.id
  101. USERBOT_ID = getme2.id
  102. BOT_NAME = (
  103. f"{getme.first_name} {getme.last_name}"
  104. if getme.last_name
  105. else getme.first_name
  106. )
  107. BOT_USERNAME = getme.username
  108. BOT_MENTION = getme.mention
  109. BOT_DC_ID = getme.dc_id
  110. USERBOT_NAME = (
  111. f"{getme2.first_name} {getme2.last_name}"
  112. if getme2.last_name
  113. else getme2.first_name
  114. )
  115. USERBOT_USERNAME = getme2.username
  116. USERBOT_MENTION = getme2.mention
  117. USERBOT_DC_ID = getme2.dc_id
  118. print("[INFO]: STARTING BOT CLIENT")
  119. app.start()
  120. print("[INFO]: STARTING USERBOT CLIENT")
  121. app2.start()
  122. print("[INFO]: LOADING UB/BOT PROFILE INFO")
  123. get_info(app, app2)
  124. if USERBOT_ID not in SUDOERS:
  125. SUDOERS.append(USERBOT_ID)