__init__.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 inspect import getfullargspec
  24. from os import path
  25. from aiohttp import ClientSession
  26. from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
  27. from pyrogram import Client
  28. from pyrogram.types import Message
  29. from pyromod import listen
  30. from Python_ARQ import ARQ
  31. is_config = path.exists("config.py")
  32. if is_config:
  33. from config import *
  34. else:
  35. from sample_config import *
  36. USERBOT_PREFIX = USERBOT_PREFIX
  37. GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
  38. SUDOERS = SUDO_USERS_ID
  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_URL)
  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"},
  60. {"$set": {"sudoers": sudoers}},
  61. upsert=True,
  62. )
  63. SUDOERS = (SUDOERS + sudoers) if sudoers else SUDOERS
  64. print("[INFO]: LOADED SUDOERS")
  65. loop = asyncio.get_event_loop()
  66. loop.run_until_complete(load_sudoers())
  67. if not HEROKU:
  68. app2 = Client(
  69. "userbot",
  70. phone_number=PHONE_NUMBER,
  71. api_id=API_ID,
  72. api_hash=API_HASH,
  73. )
  74. else:
  75. app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
  76. aiohttpsession = ClientSession()
  77. arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
  78. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  79. print("[INFO]: STARTING BOT CLIENT")
  80. app.start()
  81. print("[INFO]: STARTING USERBOT CLIENT")
  82. app2.start()
  83. print("[INFO]: GATHERING PROFILE INFO")
  84. x = app.get_me()
  85. y = app2.get_me()
  86. BOT_ID = x.id
  87. BOT_NAME = x.first_name + (x.last_name or "")
  88. BOT_USERNAME = x.username
  89. BOT_MENTION = x.mention
  90. BOT_DC_ID = x.dc_id
  91. USERBOT_ID = y.id
  92. USERBOT_NAME = y.first_name + (y.last_name or "")
  93. USERBOT_USERNAME = y.username
  94. USERBOT_MENTION = y.mention
  95. USERBOT_DC_ID = y.dc_id
  96. if USERBOT_ID not in SUDOERS:
  97. SUDOERS.append(USERBOT_ID)
  98. async def eor(msg: Message, **kwargs):
  99. func = msg.edit_text if msg.from_user.is_self else msg.reply
  100. spec = getfullargspec(func.__wrapped__).args
  101. return await func(**{k: v for k, v in kwargs.items() if k in spec})