__init__.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. from telegraph import Telegraph
  32. is_config = path.exists("config.py")
  33. if is_config:
  34. from config import *
  35. else:
  36. from sample_config import *
  37. USERBOT_PREFIX = USERBOT_PREFIX
  38. GBAN_LOG_GROUP_ID = GBAN_LOG_GROUP_ID
  39. SUDOERS = SUDO_USERS_ID
  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]: INITIALIZING DATABASE")
  48. mongo_client = MongoClient(MONGO_URL)
  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. print("[INFO]: LOADED SUDOERS")
  66. loop = asyncio.get_event_loop()
  67. loop.run_until_complete(load_sudoers())
  68. if not HEROKU:
  69. app2 = Client(
  70. "userbot",
  71. phone_number=PHONE_NUMBER,
  72. api_id=API_ID,
  73. api_hash=API_HASH,
  74. )
  75. else:
  76. app2 = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH)
  77. aiohttpsession = ClientSession()
  78. arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
  79. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  80. print("[INFO]: STARTING BOT CLIENT")
  81. app.start()
  82. print("[INFO]: STARTING USERBOT CLIENT")
  83. app2.start()
  84. print("[INFO]: GATHERING PROFILE INFO")
  85. x = app.get_me()
  86. y = app2.get_me()
  87. BOT_ID = x.id
  88. BOT_NAME = x.first_name + (x.last_name or "")
  89. BOT_USERNAME = x.username
  90. BOT_MENTION = x.mention
  91. BOT_DC_ID = x.dc_id
  92. USERBOT_ID = y.id
  93. USERBOT_NAME = y.first_name + (y.last_name or "")
  94. USERBOT_USERNAME = y.username
  95. USERBOT_MENTION = y.mention
  96. USERBOT_DC_ID = y.dc_id
  97. if USERBOT_ID not in SUDOERS:
  98. SUDOERS.append(USERBOT_ID)
  99. telegraph = Telegraph()
  100. telegraph.create_account(short_name=BOT_USERNAME)
  101. async def eor(msg: Message, **kwargs):
  102. func = msg.edit_text if msg.from_user.is_self else msg.reply
  103. spec = getfullargspec(func.__wrapped__).args
  104. return await func(**{k: v for k, v in kwargs.items() if k in spec})