__init__.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. print("[INFO]: INITIALIZING")
  22. import asyncio
  23. import logging
  24. import time
  25. from os import path
  26. from aiohttp import ClientSession
  27. from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
  28. from pyrogram import Client
  29. from Python_ARQ import ARQ
  30. # Setup logging
  31. log_file = "error.log"
  32. with open(log_file, "w") as f:
  33. f.write("PEAK OF LOG FILE")
  34. logging.basicConfig(
  35. level=logging.ERROR,
  36. format="[%(asctime)s.%(msecs)03d] %(filename)s:%(lineno)s %(levelname)s: %(message)s",
  37. datefmt="%m-%d %H:%M",
  38. filename=log_file,
  39. filemode="w",
  40. )
  41. console = logging.StreamHandler()
  42. logging.getLogger("").addHandler(console)
  43. log = logging.getLogger()
  44. is_config = path.exists("config.py")
  45. if is_config:
  46. from config import *
  47. else:
  48. from sample_config import *
  49. USERBOT_PREFIX = USERBOT_PREFIX
  50. GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
  51. SUDOERS = SUDO_USERS_ID
  52. FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
  53. WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
  54. LOG_GROUP_ID = LOG_GROUP_ID
  55. MESSAGE_DUMP_CHAT = MESSAGE_DUMP_CHAT
  56. MOD_LOAD = []
  57. MOD_NOLOAD = []
  58. bot_start_time = time.time()
  59. # MongoDB client
  60. print("[INFO]: INITIALIZING DATABASE")
  61. mongo_client = MongoClient(MONGO_DB_URI)
  62. db = mongo_client.wbb
  63. async def load_sudoers():
  64. global SUDOERS
  65. print("[INFO]: LOADING SUDOERS")
  66. sudoersdb = db.sudoers
  67. sudoers = await sudoersdb.find_one({"sudo": "sudo"})
  68. sudoers = [] if not sudoers else sudoers["sudoers"]
  69. for user_id in SUDOERS:
  70. if user_id not in sudoers:
  71. sudoers.append(user_id)
  72. await sudoersdb.update_one(
  73. {"sudo": "sudo"}, {"$set": {"sudoers": sudoers}}, upsert=True
  74. )
  75. SUDOERS = (SUDOERS + sudoers) if sudoers else SUDOERS
  76. print("[INFO]: LOADED SUDOERS")
  77. loop = asyncio.get_event_loop()
  78. loop.run_until_complete(load_sudoers())
  79. if not HEROKU:
  80. print("[INFO]: INITIALIZING USERBOT CLIENT")
  81. app2 = Client(
  82. "userbot", phone_number=PHONE_NUMBER, api_id=API_ID, api_hash=API_HASH
  83. )
  84. else:
  85. print("[INFO]: INITIALIZING USERBOT CLIENT")
  86. app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
  87. # Aiohttp Client
  88. print("[INFO]: INITIALZING AIOHTTP SESSION")
  89. aiohttpsession = ClientSession()
  90. # ARQ Client
  91. print("[INFO]: INITIALIZING ARQ CLIENT")
  92. arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
  93. # Bot client
  94. print("[INFO]: INITIALIZING BOT CLIENT")
  95. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  96. BOT_ID = 0
  97. BOT_NAME = ""
  98. BOT_USERNAME = ""
  99. BOT_MENTION = ""
  100. BOT_DC_ID = 0
  101. USERBOT_ID = 0
  102. USERBOT_NAME = ""
  103. USERBOT_USERNAME = ""
  104. USERBOT_DC_ID = 0
  105. USERBOT_MENTION = ""
  106. USERBOT_BOT_CHAT_COMMON = []
  107. def get_info(app, app2):
  108. global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID, BOT_MENTION
  109. global USERBOT_ID, USERBOT_NAME, USERBOT_USERNAME, USERBOT_DC_ID, USERBOT_MENTION
  110. global USERBOT_BOT_CHAT_COMMON
  111. getme = app.get_me()
  112. getme2 = app2.get_me()
  113. BOT_ID = getme.id
  114. USERBOT_ID = getme2.id
  115. BOT_NAME = (
  116. f"{getme.first_name} {getme.last_name}"
  117. if getme.last_name
  118. else getme.first_name
  119. )
  120. BOT_USERNAME = getme.username
  121. BOT_MENTION = getme.mention
  122. BOT_DC_ID = getme.dc_id
  123. USERBOT_NAME = (
  124. f"{getme2.first_name} {getme2.last_name}"
  125. if getme2.last_name
  126. else getme2.first_name
  127. )
  128. USERBOT_USERNAME = getme2.username
  129. USERBOT_MENTION = getme2.mention
  130. USERBOT_DC_ID = getme2.dc_id
  131. USERBOT_BOT_CHAT_COMMON = [
  132. i.id for i in app2.get_common_chats(BOT_USERNAME)
  133. ] + SPAM_CHECK_EXCEPTION_GROUPS
  134. print("[INFO]: STARTING BOT CLIENT")
  135. app.start()
  136. print("[INFO]: STARTING USERBOT CLIENT")
  137. app2.start()
  138. print("[INFO]: LOADING UB/BOT PROFILE INFO")
  139. get_info(app, app2)
  140. print("[INFO]: LOADED UB/BOT PROFILE INFO")
  141. if USERBOT_ID not in SUDOERS:
  142. SUDOERS.append(USERBOT_ID)