__init__.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 time
  22. from os import path
  23. from telegraph import Telegraph
  24. from Python_ARQ import ARQ
  25. from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
  26. import asyncio
  27. from pyromod import listen
  28. from pyrogram import Client
  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. listen = listen
  36. USERBOT_PREFIX = USERBOT_PREFIX
  37. GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
  38. SUDOERS = SUDO_USERS_ID
  39. FERNET_ENCRYPTION_KEY = FERNET_ENCRYPTION_KEY
  40. WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
  41. LOG_GROUP_ID = LOG_GROUP_ID
  42. MESSAGE_DUMP_CHAT = MESSAGE_DUMP_CHAT
  43. MOD_LOAD = []
  44. MOD_NOLOAD = []
  45. bot_start_time = time.time()
  46. # MongoDB client
  47. print("[INFO]: LOADING MONGODB")
  48. mongo_client = MongoClient(MONGO_DB_URI)
  49. db = mongo_client.wbb
  50. async def load_sudoers():
  51. global SUDOERS
  52. print("[INFO]: LOADING SUDOERS")
  53. sudoersdb = db.sudoers
  54. sudoers = await sudoersdb.find_one({"sudo": "sudo"})
  55. sudoers = [] if not sudoers else sudoers['sudoers']
  56. for user_id in SUDOERS:
  57. if user_id not in sudoers:
  58. sudoers.append(user_id)
  59. await sudoersdb.update_one(
  60. {"sudo": "sudo"},
  61. {"$set": {"sudoers": sudoers}},
  62. upsert=True
  63. )
  64. SUDOERS = (SUDOERS + sudoers) if sudoers else SUDOERS
  65. loop = asyncio.get_event_loop()
  66. loop.run_until_complete(load_sudoers())
  67. if not HEROKU:
  68. print("[INFO]: LOADING USERBOT CLIENT")
  69. app2 = Client("userbot", phone_number=PHONE_NUMBER,
  70. api_id=API_ID, api_hash=API_HASH)
  71. else:
  72. print("[INFO]: LOADING USERBOT CLIENT")
  73. app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
  74. # Bot client
  75. print("[INFO]: LOADING BOT CLIENT")
  76. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  77. # ARQ client
  78. print("[INFO]: LOADING ARQ")
  79. arq = ARQ(ARQ_API_BASE_URL)
  80. # Telegram client
  81. print("[INFO]: LOADING TELEGRAPH")
  82. telegraph = Telegraph()
  83. telegraph.create_account(short_name="wbb")
  84. BOT_ID = 0
  85. BOT_NAME = ""
  86. BOT_USERNAME = ""
  87. BOT_MENTION = ""
  88. BOT_DC_ID = 0
  89. USERBOT_ID = 0
  90. USERBOT_NAME = ""
  91. USERBOT_USERNAME = ""
  92. USERBOT_DC_ID = 0
  93. USERBOT_MENTION = ""
  94. def get_info(app, app2):
  95. global BOT_ID, BOT_NAME, BOT_USERNAME, BOT_DC_ID, BOT_MENTION
  96. global USERBOT_ID, USERBOT_NAME, USERBOT_USERNAME, USERBOT_DC_ID, USERBOT_MENTION
  97. getme = app.get_me()
  98. getme2 = app2.get_me()
  99. BOT_ID = getme.id
  100. USERBOT_ID = getme2.id
  101. if getme.last_name:
  102. BOT_NAME = getme.first_name + " " + getme.last_name
  103. else:
  104. BOT_NAME = getme.first_name
  105. BOT_USERNAME = getme.username
  106. BOT_MENTION = getme.mention
  107. BOT_DC_ID = getme.dc_id
  108. if getme2.last_name:
  109. USERBOT_NAME = getme2.first_name + " " + getme2.last_name
  110. else:
  111. USERBOT_NAME = getme2.first_name
  112. USERBOT_USERNAME = getme2.username
  113. USERBOT_MENTION = getme2.mention
  114. USERBOT_DC_ID = getme2.dc_id
  115. print("[INFO]: STARTING BOT CLIENT")
  116. app.start()
  117. print("[INFO]: STARTING USERBOT CLIENT")
  118. app2.start()
  119. get_info(app, app2)
  120. if USERBOT_ID not in SUDOERS:
  121. SUDOERS.append(USERBOT_ID)