__init__.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. """
  2. MIT License
  3. Copyright (c) 2023 TheHamkerCat
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. """
  20. import asyncio
  21. import time
  22. from inspect import getfullargspec
  23. from os import path
  24. from aiohttp import ClientSession
  25. from motor.motor_asyncio import AsyncIOMotorClient as MongoClient
  26. from pyrogram import Client, filters
  27. from pyrogram.types import Message
  28. from pyromod import listen
  29. from Python_ARQ import ARQ
  30. from telegraph import Telegraph
  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. WELCOME_DELAY_KICK_SEC = WELCOME_DELAY_KICK_SEC
  39. LOG_GROUP_ID = LOG_GROUP_ID
  40. MESSAGE_DUMP_CHAT = MESSAGE_DUMP_CHAT
  41. MOD_LOAD = []
  42. MOD_NOLOAD = []
  43. SUDOERS = filters.user()
  44. bot_start_time = time.time()
  45. class Log:
  46. def __init__(self, save_to_file=False, file_name="wbb.log"):
  47. self.save_to_file = save_to_file
  48. self.file_name = file_name
  49. def info(self, msg):
  50. print(f"[+]: {msg}")
  51. if self.save_to_file:
  52. with open(self.file_name, "a") as f:
  53. f.write(f"[INFO]({time.ctime(time.time())}): {msg}\n")
  54. def error(self, msg):
  55. print(f"[-]: {msg}")
  56. if self.save_to_file:
  57. with open(self.file_name, "a") as f:
  58. f.write(f"[ERROR]({time.ctime(time.time())}): {msg}\n")
  59. log = Log(True, "bot.log")
  60. # MongoDB client
  61. log.info("Initializing MongoDB client")
  62. mongo_client = MongoClient(MONGO_URL)
  63. db = mongo_client.wbb
  64. async def load_sudoers():
  65. global SUDOERS
  66. log.info("Loading sudoers")
  67. sudoersdb = db.sudoers
  68. sudoers = await sudoersdb.find_one({"sudo": "sudo"})
  69. sudoers = [] if not sudoers else sudoers["sudoers"]
  70. for user_id in SUDO_USERS_ID:
  71. SUDOERS.add(user_id)
  72. if user_id not in sudoers:
  73. sudoers.append(user_id)
  74. await sudoersdb.update_one(
  75. {"sudo": "sudo"},
  76. {"$set": {"sudoers": sudoers}},
  77. upsert=True,
  78. )
  79. if sudoers:
  80. for user_id in sudoers:
  81. SUDOERS.add(user_id)
  82. loop = asyncio.get_event_loop()
  83. loop.run_until_complete(load_sudoers())
  84. if not SESSION_STRING:
  85. app2 = Client(
  86. name="userbot",
  87. api_id=API_ID,
  88. api_hash=API_HASH,
  89. phone_number=PHONE_NUMBER,
  90. )
  91. else:
  92. app2 = Client(
  93. name="userbot", api_id=API_ID, api_hash=API_HASH, session_string=SESSION_STRING
  94. )
  95. aiohttpsession = ClientSession()
  96. arq = ARQ(ARQ_API_URL, ARQ_API_KEY, aiohttpsession)
  97. app = Client("wbb", bot_token=BOT_TOKEN, api_id=API_ID, api_hash=API_HASH)
  98. log.info("Starting bot client")
  99. app.start()
  100. log.info("Starting userbot client")
  101. app2.start()
  102. log.info("Gathering profile info")
  103. x = app.get_me()
  104. y = app2.get_me()
  105. BOT_ID = x.id
  106. BOT_NAME = x.first_name + (x.last_name or "")
  107. BOT_USERNAME = x.username
  108. BOT_MENTION = x.mention
  109. BOT_DC_ID = x.dc_id
  110. USERBOT_ID = y.id
  111. USERBOT_NAME = y.first_name + (y.last_name or "")
  112. USERBOT_USERNAME = y.username
  113. USERBOT_MENTION = y.mention
  114. USERBOT_DC_ID = y.dc_id
  115. if USERBOT_ID not in SUDOERS:
  116. SUDOERS.add(USERBOT_ID)
  117. log.info("Initializing Telegraph client")
  118. telegraph = Telegraph()
  119. telegraph.create_account(short_name=BOT_USERNAME)
  120. async def eor(msg: Message, **kwargs):
  121. func = (
  122. (msg.edit_text if msg.from_user.is_self else msg.reply)
  123. if msg.from_user
  124. else msg.reply
  125. )
  126. spec = getfullargspec(func.__wrapped__).args
  127. return await func(**{k: v for k, v in kwargs.items() if k in spec})