Spaces:
Runtime error
Runtime error
Upload 87 files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- Hellbot/__init__.py +60 -0
- Hellbot/__main__.py +33 -0
- Hellbot/core/__init__.py +19 -0
- Hellbot/core/clients.py +232 -0
- Hellbot/core/config.py +155 -0
- Hellbot/core/database.py +584 -0
- Hellbot/core/initializer.py +94 -0
- Hellbot/core/logger.py +19 -0
- Hellbot/functions/__init__.py +0 -0
- Hellbot/functions/admins.py +24 -0
- Hellbot/functions/convert.py +98 -0
- Hellbot/functions/driver.py +318 -0
- Hellbot/functions/formatter.py +94 -0
- Hellbot/functions/images.py +389 -0
- Hellbot/functions/media.py +192 -0
- Hellbot/functions/paste.py +49 -0
- Hellbot/functions/scraping.py +528 -0
- Hellbot/functions/sticker.py +135 -0
- Hellbot/functions/templates.py +466 -0
- Hellbot/functions/tools.py +139 -0
- Hellbot/functions/utility.py +241 -0
- Hellbot/plugins/__init__.py +0 -0
- Hellbot/plugins/bot/__init__.py +29 -0
- Hellbot/plugins/bot/bot.py +60 -0
- Hellbot/plugins/bot/callbacks.py +279 -0
- Hellbot/plugins/bot/forcesub.py +226 -0
- Hellbot/plugins/bot/inline.py +39 -0
- Hellbot/plugins/bot/sessions.py +183 -0
- Hellbot/plugins/bot/users.py +82 -0
- Hellbot/plugins/btnsG.py +106 -0
- Hellbot/plugins/btnsK.py +45 -0
- Hellbot/plugins/decorator.py +67 -0
- Hellbot/plugins/help.py +132 -0
- Hellbot/plugins/user/__init__.py +16 -0
- Hellbot/plugins/user/admins.py +510 -0
- Hellbot/plugins/user/afk.py +157 -0
- Hellbot/plugins/user/anime.py +184 -0
- Hellbot/plugins/user/antiflood.py +200 -0
- Hellbot/plugins/user/archiver.py +99 -0
- Hellbot/plugins/user/autopost.py +143 -0
- Hellbot/plugins/user/blacklist.py +78 -0
- Hellbot/plugins/user/bot.py +164 -0
- Hellbot/plugins/user/carbon.py +73 -0
- Hellbot/plugins/user/climate.py +140 -0
- Hellbot/plugins/user/clone.py +106 -0
- Hellbot/plugins/user/convert.py +216 -0
- Hellbot/plugins/user/core.py +321 -0
- Hellbot/plugins/user/downloads.py +85 -0
- Hellbot/plugins/user/echo.py +91 -0
- Hellbot/plugins/user/eval.py +272 -0
Hellbot/__init__.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
from platform import python_version
|
4 |
+
|
5 |
+
import heroku3
|
6 |
+
from pyrogram import __version__ as pyrogram_version
|
7 |
+
|
8 |
+
from .core import LOGS, Config
|
9 |
+
|
10 |
+
START_TIME = time.time()
|
11 |
+
|
12 |
+
|
13 |
+
__version__ = {
|
14 |
+
"hellbot": "3.0",
|
15 |
+
"pyrogram": pyrogram_version,
|
16 |
+
"python": python_version(),
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
try:
|
21 |
+
if Config.HEROKU_APIKEY is not None and Config.HEROKU_APPNAME is not None:
|
22 |
+
HEROKU_APP = heroku3.from_key(Config.HEROKU_APIKEY).apps()[
|
23 |
+
Config.HEROKU_APPNAME
|
24 |
+
]
|
25 |
+
else:
|
26 |
+
HEROKU_APP = None
|
27 |
+
except Exception as e:
|
28 |
+
LOGS.error(f"Heroku Api - {e}")
|
29 |
+
HEROKU_APP = None
|
30 |
+
|
31 |
+
|
32 |
+
if Config.API_HASH is None:
|
33 |
+
LOGS.error("Please set your API_HASH !")
|
34 |
+
quit(1)
|
35 |
+
|
36 |
+
if Config.API_ID == 0:
|
37 |
+
LOGS.error("Please set your API_ID !")
|
38 |
+
quit(1)
|
39 |
+
|
40 |
+
if Config.BOT_TOKEN is None:
|
41 |
+
LOGS.error("Please set your BOT_TOKEN !")
|
42 |
+
quit(1)
|
43 |
+
|
44 |
+
if Config.DATABASE_URL is None:
|
45 |
+
LOGS.error("Please set your DATABASE_URL !")
|
46 |
+
quit(1)
|
47 |
+
|
48 |
+
if Config.LOGGER_ID == 0:
|
49 |
+
LOGS.error("Please set your LOGGER_ID !")
|
50 |
+
quit(1)
|
51 |
+
|
52 |
+
if Config.OWNER_ID == 0:
|
53 |
+
LOGS.error("Please set your OWNER_ID !")
|
54 |
+
quit(1)
|
55 |
+
|
56 |
+
if not os.path.isdir(Config.DWL_DIR):
|
57 |
+
os.makedirs(Config.DWL_DIR)
|
58 |
+
|
59 |
+
if not os.path.isdir(Config.TEMP_DIR):
|
60 |
+
os.makedirs(Config.TEMP_DIR)
|
Hellbot/__main__.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyrogram import idle
|
2 |
+
|
3 |
+
from Hellbot import __version__
|
4 |
+
from Hellbot.core import (
|
5 |
+
Config,
|
6 |
+
ForcesubSetup,
|
7 |
+
GachaBotsSetup,
|
8 |
+
TemplateSetup,
|
9 |
+
UserSetup,
|
10 |
+
db,
|
11 |
+
hellbot,
|
12 |
+
)
|
13 |
+
from Hellbot.functions.tools import initialize_git
|
14 |
+
from Hellbot.functions.utility import BList, Flood, TGraph
|
15 |
+
|
16 |
+
|
17 |
+
async def main():
|
18 |
+
await hellbot.startup()
|
19 |
+
await db.connect()
|
20 |
+
await UserSetup()
|
21 |
+
await ForcesubSetup()
|
22 |
+
await GachaBotsSetup()
|
23 |
+
await TemplateSetup()
|
24 |
+
await Flood.updateFromDB()
|
25 |
+
await BList.updateBlacklists()
|
26 |
+
await TGraph.setup()
|
27 |
+
await initialize_git(Config.PLUGINS_REPO)
|
28 |
+
await hellbot.start_message(__version__)
|
29 |
+
await idle()
|
30 |
+
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
hellbot.run(main())
|
Hellbot/core/__init__.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from .clients import hellbot
|
2 |
+
from .config import ENV, Config, Limits, Symbols
|
3 |
+
from .database import db
|
4 |
+
from .initializer import ForcesubSetup, GachaBotsSetup, TemplateSetup, UserSetup
|
5 |
+
from .logger import LOGS
|
6 |
+
|
7 |
+
__all__ = [
|
8 |
+
"hellbot",
|
9 |
+
"ENV",
|
10 |
+
"Config",
|
11 |
+
"Limits",
|
12 |
+
"Symbols",
|
13 |
+
"db",
|
14 |
+
"ForcesubSetup",
|
15 |
+
"GachaBotsSetup",
|
16 |
+
"TemplateSetup",
|
17 |
+
"UserSetup",
|
18 |
+
"LOGS",
|
19 |
+
]
|
Hellbot/core/clients.py
ADDED
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import glob
|
3 |
+
import importlib
|
4 |
+
import os
|
5 |
+
import sys
|
6 |
+
from pathlib import Path
|
7 |
+
|
8 |
+
import pyroaddon # pylint: disable=unused-import
|
9 |
+
from pyrogram import Client
|
10 |
+
from pyrogram.enums import ParseMode
|
11 |
+
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
|
12 |
+
|
13 |
+
from .config import ENV, Config, Symbols
|
14 |
+
from .database import db
|
15 |
+
from .logger import LOGS
|
16 |
+
|
17 |
+
|
18 |
+
class HellClient(Client):
|
19 |
+
def __init__(self) -> None:
|
20 |
+
self.users: list[Client] = []
|
21 |
+
self.bot: Client = Client(
|
22 |
+
name="HellBot",
|
23 |
+
api_id=Config.API_ID,
|
24 |
+
api_hash=Config.API_HASH,
|
25 |
+
bot_token=Config.BOT_TOKEN,
|
26 |
+
plugins=dict(root="Hellbot.plugins.bot"),
|
27 |
+
)
|
28 |
+
|
29 |
+
async def start_user(self) -> None:
|
30 |
+
sessions = await db.get_all_sessions()
|
31 |
+
for i, session in enumerate(sessions):
|
32 |
+
try:
|
33 |
+
client = Client(
|
34 |
+
name=f"HellUser#{i + 1}",
|
35 |
+
api_id=Config.API_ID,
|
36 |
+
api_hash=Config.API_HASH,
|
37 |
+
session_string=session["session"],
|
38 |
+
)
|
39 |
+
await client.start()
|
40 |
+
me = await client.get_me()
|
41 |
+
self.users.append(client)
|
42 |
+
LOGS.info(
|
43 |
+
f"{Symbols.arrow_right * 2} Started User {i + 1}: '{me.first_name}' {Symbols.arrow_left * 2}"
|
44 |
+
)
|
45 |
+
is_in_logger = await self.validate_logger(client)
|
46 |
+
if not is_in_logger:
|
47 |
+
LOGS.warning(
|
48 |
+
f"Client #{i+1}: '{me.first_name}' is not in Logger Group! Check and add manually for proper functioning."
|
49 |
+
)
|
50 |
+
try:
|
51 |
+
await client.join_chat("https://t.me/+wQyUMn4891Q2OTVh") # Channel
|
52 |
+
except:
|
53 |
+
pass
|
54 |
+
# try:
|
55 |
+
# await client.join_chat("https://t.me/+P4Ekwk7P7Rk3NzA9") # Group
|
56 |
+
# except:
|
57 |
+
# pass
|
58 |
+
except Exception as e:
|
59 |
+
LOGS.error(f"{i + 1}: {e}")
|
60 |
+
continue
|
61 |
+
|
62 |
+
async def start_bot(self) -> None:
|
63 |
+
await self.bot.start()
|
64 |
+
me = await self.bot.get_me()
|
65 |
+
LOGS.info(
|
66 |
+
f"{Symbols.arrow_right * 2} Started HellBot Client: '{me.username}' {Symbols.arrow_left * 2}"
|
67 |
+
)
|
68 |
+
|
69 |
+
async def load_plugin(self) -> None:
|
70 |
+
count = 0
|
71 |
+
files = glob.glob("Hellbot/plugins/user/*.py")
|
72 |
+
unload = await db.get_env(ENV.unload_plugins) or ""
|
73 |
+
unload = unload.split(" ")
|
74 |
+
for file in files:
|
75 |
+
with open(file) as f:
|
76 |
+
path = Path(f.name)
|
77 |
+
shortname = path.stem.replace(".py", "")
|
78 |
+
if shortname in unload:
|
79 |
+
os.remove(Path(f"Hellbot/plugins/user/{shortname}.py"))
|
80 |
+
continue
|
81 |
+
if shortname.startswith("__"):
|
82 |
+
continue
|
83 |
+
fpath = Path(f"Hellbot/plugins/user/{shortname}.py")
|
84 |
+
name = "Hellbot.plugins.user." + shortname
|
85 |
+
spec = importlib.util.spec_from_file_location(name, fpath)
|
86 |
+
load = importlib.util.module_from_spec(spec)
|
87 |
+
spec.loader.exec_module(load)
|
88 |
+
sys.modules["Hellbot.plugins.user." + shortname] = load
|
89 |
+
count += 1
|
90 |
+
f.close()
|
91 |
+
LOGS.info(
|
92 |
+
f"{Symbols.bullet * 3} Loaded User Plugin: '{count}' {Symbols.bullet * 3}"
|
93 |
+
)
|
94 |
+
|
95 |
+
async def validate_logger(self, client: Client) -> bool:
|
96 |
+
try:
|
97 |
+
await client.get_chat_member(Config.LOGGER_ID, "me")
|
98 |
+
return True
|
99 |
+
except Exception:
|
100 |
+
return await self.join_logger(client)
|
101 |
+
|
102 |
+
async def join_logger(self, client: Client) -> bool:
|
103 |
+
try:
|
104 |
+
invite_link = await self.bot.export_chat_invite_link(Config.LOGGER_ID)
|
105 |
+
await client.join_chat(invite_link)
|
106 |
+
return True
|
107 |
+
except Exception:
|
108 |
+
return False
|
109 |
+
|
110 |
+
async def start_message(self, version: dict) -> None:
|
111 |
+
await self.bot.send_animation(
|
112 |
+
Config.LOGGER_ID,
|
113 |
+
"https://te.legra.ph/file/8deca5343c64d9db9401f.mp4",
|
114 |
+
f"**{Symbols.check_mark} 𝖧𝖾𝗅𝗅𝖡𝗈𝗍 𝗂𝗌 𝗇𝗈𝗐 𝖮𝗇𝗅𝗂𝗇𝖾!**\n\n"
|
115 |
+
f"**{Symbols.triangle_right} 𝖢𝗅𝗂𝖾𝗇𝗍𝗌:** `{len(self.users)}`\n"
|
116 |
+
f"**{Symbols.triangle_right} 𝖯𝗅𝗎𝗀𝗂𝗇𝗌:** `{len(Config.CMD_MENU)}`\n"
|
117 |
+
f"**{Symbols.triangle_right} 𝖢𝗈𝗆𝗆𝖺𝗇𝖽𝗌:** `{len(Config.CMD_INFO)}`\n"
|
118 |
+
f"**{Symbols.triangle_right} 𝖲𝗍𝖺𝗇 𝖴𝗌𝖾𝗋𝗌:** `{len(Config.STAN_USERS)}`\n"
|
119 |
+
f"**{Symbols.triangle_right} 𝖠𝗎𝗍𝗁 𝖴𝗌𝖾𝗋𝗌:** `{len(Config.AUTH_USERS)}`\n\n"
|
120 |
+
f"**{Symbols.triangle_right} 𝖧𝖾𝗅𝗅𝖡𝗈𝗍 𝖵𝖾𝗋𝗌𝗂𝗈𝗇:** `{version['hellbot']}`\n"
|
121 |
+
f"**{Symbols.triangle_right} 𝖯𝗒𝗋𝗈𝗀𝗋𝖺𝗆 𝖵𝖾𝗋𝗌𝗂𝗈𝗇:** `{version['pyrogram']}`\n"
|
122 |
+
f"**{Symbols.triangle_right} 𝖯𝗒𝗍𝗁𝗈𝗇 𝖵𝖾𝗋𝗌𝗂𝗈𝗇:** `{version['python']}`\n\n"
|
123 |
+
f"**</> @HellBot_Networks**",
|
124 |
+
parse_mode=ParseMode.MARKDOWN,
|
125 |
+
disable_notification=True,
|
126 |
+
reply_markup=InlineKeyboardMarkup(
|
127 |
+
[
|
128 |
+
[
|
129 |
+
InlineKeyboardButton("💫 Start Me", url=f"https://t.me/{self.bot.me.username}?start=start"),
|
130 |
+
InlineKeyboardButton("💖 Repo", url="https://github.com/The-HellBot/HellBot"),
|
131 |
+
],
|
132 |
+
[
|
133 |
+
InlineKeyboardButton("🍀 HellBot Networks 🍀", url="https://t.me/hellbot_networks"),
|
134 |
+
],
|
135 |
+
]
|
136 |
+
),
|
137 |
+
)
|
138 |
+
|
139 |
+
async def startup(self) -> None:
|
140 |
+
LOGS.info(
|
141 |
+
f"{Symbols.bullet * 3} Starting HellBot Client & User {Symbols.bullet * 3}"
|
142 |
+
)
|
143 |
+
await self.start_bot()
|
144 |
+
await self.start_user()
|
145 |
+
await self.load_plugin()
|
146 |
+
|
147 |
+
|
148 |
+
class CustomMethods(HellClient):
|
149 |
+
async def input(self, message: Message) -> str:
|
150 |
+
"""Get the input from the user"""
|
151 |
+
if len(message.command) < 2:
|
152 |
+
output = ""
|
153 |
+
|
154 |
+
else:
|
155 |
+
try:
|
156 |
+
output = message.text.split(" ", 1)[1].strip() or ""
|
157 |
+
except IndexError:
|
158 |
+
output = ""
|
159 |
+
|
160 |
+
return output
|
161 |
+
|
162 |
+
async def edit(
|
163 |
+
self,
|
164 |
+
message: Message,
|
165 |
+
text: str,
|
166 |
+
parse_mode: ParseMode = ParseMode.DEFAULT,
|
167 |
+
no_link_preview: bool = True,
|
168 |
+
) -> Message:
|
169 |
+
"""Edit or Reply to a message, if possible"""
|
170 |
+
if message.from_user and message.from_user.id in Config.STAN_USERS:
|
171 |
+
if message.reply_to_message:
|
172 |
+
return await message.reply_to_message.reply_text(
|
173 |
+
text,
|
174 |
+
parse_mode=parse_mode,
|
175 |
+
disable_web_page_preview=no_link_preview,
|
176 |
+
)
|
177 |
+
return await message.reply_text(
|
178 |
+
text, parse_mode=parse_mode, disable_web_page_preview=no_link_preview
|
179 |
+
)
|
180 |
+
return await message.edit_text(
|
181 |
+
text, parse_mode=parse_mode, disable_web_page_preview=no_link_preview
|
182 |
+
)
|
183 |
+
|
184 |
+
async def _delete(self, message: Message, delay: int = 0) -> None:
|
185 |
+
"""Delete a message after a certain period of time"""
|
186 |
+
await asyncio.sleep(delay)
|
187 |
+
await message.delete()
|
188 |
+
|
189 |
+
async def delete(
|
190 |
+
self, message: Message, text: str, delete: int = 10, in_background: bool = True
|
191 |
+
) -> None:
|
192 |
+
"""Edit a message and delete it after a certain period of time"""
|
193 |
+
to_del = await self.edit(message, text)
|
194 |
+
if in_background:
|
195 |
+
asyncio.create_task(self._delete(to_del, delete))
|
196 |
+
else:
|
197 |
+
await self._delete(to_del, delete)
|
198 |
+
|
199 |
+
async def error(self, message: Message, text: str, delete: int = 10) -> None:
|
200 |
+
"""Edit an error message and delete it after a certain period of time if mentioned"""
|
201 |
+
to_del = await self.edit(message, f"{Symbols.cross_mark} **Error:** \n\n{text}")
|
202 |
+
if delete:
|
203 |
+
asyncio.create_task(self._delete(to_del, delete))
|
204 |
+
|
205 |
+
async def _log(self, tag: str, text: str, file: str = None) -> None:
|
206 |
+
"""Log a message to the Logger Group"""
|
207 |
+
msg = f"**#{tag.upper()}**\n\n{text}"
|
208 |
+
try:
|
209 |
+
if file:
|
210 |
+
try:
|
211 |
+
await self.bot.send_document(Config.LOGGER_ID, file, caption=msg)
|
212 |
+
except:
|
213 |
+
await self.bot.send_message(
|
214 |
+
Config.LOGGER_ID, msg, disable_web_page_preview=True
|
215 |
+
)
|
216 |
+
else:
|
217 |
+
await self.bot.send_message(
|
218 |
+
Config.LOGGER_ID, msg, disable_web_page_preview=True
|
219 |
+
)
|
220 |
+
except Exception as e:
|
221 |
+
raise Exception(f"{Symbols.cross_mark} LogErr: {e}")
|
222 |
+
|
223 |
+
async def check_and_log(self, tag: str, text: str, file: str = None) -> None:
|
224 |
+
"""Check if :
|
225 |
+
\n-> the Logger Group is available
|
226 |
+
\n-> the logging is enabled"""
|
227 |
+
status = await db.get_env(ENV.is_logger)
|
228 |
+
if status and status.lower() == "true":
|
229 |
+
await self._log(tag, text, file)
|
230 |
+
|
231 |
+
|
232 |
+
hellbot = CustomMethods()
|
Hellbot/core/config.py
ADDED
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from os import getenv
|
2 |
+
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
from pyrogram import filters
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
|
8 |
+
|
9 |
+
class Config:
|
10 |
+
# editable configs
|
11 |
+
API_HASH = getenv("API_HASH", None)
|
12 |
+
API_ID = int(getenv("API_ID", 0))
|
13 |
+
BOT_TOKEN = getenv("BOT_TOKEN", None)
|
14 |
+
DATABASE_URL = getenv("DATABASE_URL", None)
|
15 |
+
HANDLERS = getenv("HANDLERS", ". ! ?").strip().split()
|
16 |
+
LOGGER_ID = int(getenv("LOGGER_ID", 0))
|
17 |
+
OWNER_ID = int(getenv("OWNER_ID", 0))
|
18 |
+
|
19 |
+
# heroku related configs
|
20 |
+
HEROKU_APPNAME = getenv("HEROKU_APPNAME", None)
|
21 |
+
HEROKU_APIKEY = getenv("HEROKU_APIKEY", None)
|
22 |
+
|
23 |
+
# github related configs
|
24 |
+
PLUGINS_REPO = getenv("PLUGINS_REPO", "The-HellBot/Plugins")
|
25 |
+
DEPLOY_REPO = getenv("DEPLOY_REPO", "The-HellBot/Hellbot")
|
26 |
+
|
27 |
+
# storage dir: you may or may not edit
|
28 |
+
DWL_DIR = "./downloads/"
|
29 |
+
TEMP_DIR = "./temp/"
|
30 |
+
CHROME_BIN = getenv("CHROME_BIN", "/app/.chrome-for-testing/chrome-linux64/chrome")
|
31 |
+
CHROME_DRIVER = getenv(
|
32 |
+
"CHROME_DRIVER", "/app/.chrome-for-testing/chromedriver-linux64/chromedriver"
|
33 |
+
)
|
34 |
+
FONT_PATH = "./Hellbot/resources/fonts/Montserrat.ttf"
|
35 |
+
|
36 |
+
# users config: do not edit
|
37 |
+
AUTH_USERS = filters.user()
|
38 |
+
BANNED_USERS = filters.user()
|
39 |
+
GACHA_BOTS = filters.user()
|
40 |
+
MUTED_USERS = filters.user()
|
41 |
+
DEVS = filters.user([1432756163, 1874070588, 1533682758])
|
42 |
+
STAN_USERS = filters.user()
|
43 |
+
FORCESUBS = filters.chat()
|
44 |
+
|
45 |
+
# Global config: do not edit
|
46 |
+
AFK_CACHE = {}
|
47 |
+
BOT_CMD_INFO = {}
|
48 |
+
BOT_CMD_MENU = {}
|
49 |
+
BOT_HELP = {}
|
50 |
+
CMD_INFO = {}
|
51 |
+
CMD_MENU = {}
|
52 |
+
HELP_DICT = {}
|
53 |
+
TEMPLATES = {}
|
54 |
+
|
55 |
+
|
56 |
+
class ENV:
|
57 |
+
"""Database ENV Names"""
|
58 |
+
|
59 |
+
airing_template = "AIRING_TEMPLATE"
|
60 |
+
airpollution_template = "AIRPOLLUTION_TEMPLATE"
|
61 |
+
alive_pic = "ALIVE_PIC"
|
62 |
+
alive_template = "ALIVE_TEMPLATE"
|
63 |
+
anilist_user_template = "ANILIST_USER_TEMPLATE"
|
64 |
+
anime_template = "ANIME_TEMPLATE"
|
65 |
+
btn_in_help = "BUTTONS_IN_HELP"
|
66 |
+
character_template = "CHARACTER_TEMPLATE"
|
67 |
+
chat_info_template = "CHAT_INFO_TEMPLATE"
|
68 |
+
climate_api = "CLIMATE_API"
|
69 |
+
climate_template = "CLIMATE_TEMPLATE"
|
70 |
+
command_template = "COMMAND_TEMPLATE"
|
71 |
+
currency_api = "CURRENCY_API"
|
72 |
+
custom_pmpermit = "CUSTOM_PMPERMIT"
|
73 |
+
gban_template = "GBAN_TEMPLATE"
|
74 |
+
github_user_template = "GITHUB_USER_TEMPLATE"
|
75 |
+
help_emoji = "HELP_EMOJI"
|
76 |
+
help_template = "HELP_TEMPLATE"
|
77 |
+
is_logger = "IS_LOGGER"
|
78 |
+
lyrics_api = "LYRICS_API"
|
79 |
+
manga_template = "MANGA_TEMPLATE"
|
80 |
+
ocr_api = "OCR_API"
|
81 |
+
ping_pic = "PING_PIC"
|
82 |
+
ping_template = "PING_TEMPLATE"
|
83 |
+
pm_logger = "PM_LOGGER"
|
84 |
+
pm_max_spam = "PM_MAX_SPAM"
|
85 |
+
pmpermit = "PMPERMIT"
|
86 |
+
pmpermit_pic = "PMPERMIT_PIC"
|
87 |
+
remove_bg_api = "REMOVE_BG_API"
|
88 |
+
thumbnail_url = "THUMBNAIL_URL"
|
89 |
+
statistics_template = "STATISTICS_TEMPLATE"
|
90 |
+
sticker_packname = "STICKER_PACKNAME"
|
91 |
+
tag_logger = "TAG_LOGGER"
|
92 |
+
telegraph_account = "TELEGRAPH_ACCOUNT"
|
93 |
+
time_zone = "TIME_ZONE"
|
94 |
+
unload_plugins = "UNLOAD_PLUGINS"
|
95 |
+
unsplash_api = "UNSPLASH_API"
|
96 |
+
usage_template = "USAGE_TEMPLATE"
|
97 |
+
user_info_template = "USER_INFO_TEMPLATE"
|
98 |
+
|
99 |
+
|
100 |
+
class Limits:
|
101 |
+
AdminRoleLength = 16
|
102 |
+
AdminsLimit = 50
|
103 |
+
BioLength = 70
|
104 |
+
BotDescriptionLength = 512
|
105 |
+
BotInfoLength = 120
|
106 |
+
BotsLimit = 20
|
107 |
+
CaptionLength = 1024
|
108 |
+
ChannelGroupsLimit = 500
|
109 |
+
ChatTitleLength = 128
|
110 |
+
FileNameLength = 60
|
111 |
+
MessageLength = 4096
|
112 |
+
NameLength = 64
|
113 |
+
PremiumBioLength = 140
|
114 |
+
PremiumCaptionLength = 2048
|
115 |
+
PremiumChannelGroupsLimit = 1000
|
116 |
+
StickerAniamtedLimit = 50
|
117 |
+
StickerPackNameLength = 64
|
118 |
+
StickerStaticLimit = 120
|
119 |
+
|
120 |
+
|
121 |
+
class Symbols:
|
122 |
+
anchor = "⚘"
|
123 |
+
arrow_left = "«"
|
124 |
+
arrow_right = "»"
|
125 |
+
back = "🔙 back"
|
126 |
+
bullet = "•"
|
127 |
+
check_mark = "✔"
|
128 |
+
close = "🗑️"
|
129 |
+
cross_mark = "✘"
|
130 |
+
diamond_1 = "◇"
|
131 |
+
diamond_2 = "◈"
|
132 |
+
next = "⤚ next"
|
133 |
+
previous = "prev ⤙"
|
134 |
+
radio_select = "◉"
|
135 |
+
radio_unselect = "〇"
|
136 |
+
triangle_left = "◂"
|
137 |
+
triangle_right = "▸"
|
138 |
+
|
139 |
+
|
140 |
+
os_configs = [
|
141 |
+
"API_HASH",
|
142 |
+
"API_ID",
|
143 |
+
"BOT_TOKEN",
|
144 |
+
"DATABASE_URL",
|
145 |
+
"DEPLOY_REPO",
|
146 |
+
"HANDLERS",
|
147 |
+
"HEROKU_APIKEY",
|
148 |
+
"HEROKU_APPNAME",
|
149 |
+
"LOGGER_ID",
|
150 |
+
"OWNER_ID",
|
151 |
+
"PLUGINS_REPO",
|
152 |
+
]
|
153 |
+
all_env: list[str] = [
|
154 |
+
value for key, value in ENV.__dict__.items() if not key.startswith("__")
|
155 |
+
]
|
Hellbot/core/database.py
ADDED
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datetime
|
2 |
+
import time
|
3 |
+
|
4 |
+
from motor import motor_asyncio
|
5 |
+
from motor.core import AgnosticClient
|
6 |
+
|
7 |
+
from .config import Config, Symbols
|
8 |
+
from .logger import LOGS
|
9 |
+
|
10 |
+
|
11 |
+
class Database:
|
12 |
+
def __init__(self, uri: str) -> None:
|
13 |
+
self.client: AgnosticClient = motor_asyncio.AsyncIOMotorClient(uri)
|
14 |
+
self.db = self.client["Hellbot"]
|
15 |
+
|
16 |
+
self.afk = self.db["afk"]
|
17 |
+
self.antiflood = self.db["antiflood"]
|
18 |
+
self.autopost = self.db["autopost"]
|
19 |
+
self.blacklist = self.db["blacklist"]
|
20 |
+
self.echo = self.db["echo"]
|
21 |
+
self.env = self.db["env"]
|
22 |
+
self.filter = self.db["filter"]
|
23 |
+
self.forcesub = self.db["forcesub"]
|
24 |
+
self.gachabots = self.db["gachabots"]
|
25 |
+
self.gban = self.db["gban"]
|
26 |
+
self.gmute = self.db["gmute"]
|
27 |
+
self.greetings = self.db["greetings"]
|
28 |
+
self.mute = self.db["mute"]
|
29 |
+
self.pmpermit = self.db["pmpermit"]
|
30 |
+
self.session = self.db["session"]
|
31 |
+
self.snips = self.db["snips"]
|
32 |
+
self.stan_users = self.db["stan_users"]
|
33 |
+
|
34 |
+
async def connect(self):
|
35 |
+
try:
|
36 |
+
await self.client.admin.command("ping")
|
37 |
+
LOGS.info(
|
38 |
+
f"{Symbols.bullet * 3} Database Connection Established! {Symbols.bullet * 3}"
|
39 |
+
)
|
40 |
+
except Exception as e:
|
41 |
+
LOGS.info(f"{Symbols.cross_mark} DatabaseErr: {e} ")
|
42 |
+
quit(1)
|
43 |
+
|
44 |
+
def get_datetime(self) -> str:
|
45 |
+
return datetime.datetime.now().strftime("%d/%m/%Y - %H:%M")
|
46 |
+
|
47 |
+
async def set_env(self, name: str, value: str) -> None:
|
48 |
+
await self.env.update_one(
|
49 |
+
{"name": name}, {"$set": {"value": value}}, upsert=True
|
50 |
+
)
|
51 |
+
|
52 |
+
async def get_env(self, name: str) -> str | None:
|
53 |
+
if await self.is_env(name):
|
54 |
+
data = await self.env.find_one({"name": name})
|
55 |
+
return data["value"]
|
56 |
+
return None
|
57 |
+
|
58 |
+
async def rm_env(self, name: str) -> None:
|
59 |
+
await self.env.delete_one({"name": name})
|
60 |
+
|
61 |
+
async def is_env(self, name: str) -> bool:
|
62 |
+
if await self.env.find_one({"name": name}):
|
63 |
+
return True
|
64 |
+
return False
|
65 |
+
|
66 |
+
async def get_all_env(self) -> list:
|
67 |
+
return [i async for i in self.env.find({})]
|
68 |
+
|
69 |
+
async def is_stan(self, client: int, user_id: int) -> bool:
|
70 |
+
if await self.stan_users.find_one({"client": client, "user_id": user_id}):
|
71 |
+
return True
|
72 |
+
return False
|
73 |
+
|
74 |
+
async def add_stan(self, client: int, user_id: int) -> bool:
|
75 |
+
if await self.is_stan(client, user_id):
|
76 |
+
return False
|
77 |
+
await self.stan_users.insert_one(
|
78 |
+
{"client": client, "user_id": user_id, "date": self.get_datetime()}
|
79 |
+
)
|
80 |
+
return True
|
81 |
+
|
82 |
+
async def rm_stan(self, client: int, user_id: int) -> bool:
|
83 |
+
if not await self.is_stan(client, user_id):
|
84 |
+
return False
|
85 |
+
await self.stan_users.delete_one({"client": client, "user_id": user_id})
|
86 |
+
return True
|
87 |
+
|
88 |
+
async def get_stans(self, client: int) -> list:
|
89 |
+
return [i async for i in self.stan_users.find({"client": client})]
|
90 |
+
|
91 |
+
async def get_all_stans(self) -> list:
|
92 |
+
return [i async for i in self.stan_users.find({})]
|
93 |
+
|
94 |
+
async def is_session(self, user_id: int) -> bool:
|
95 |
+
if await self.session.find_one({"user_id": user_id}):
|
96 |
+
return True
|
97 |
+
return False
|
98 |
+
|
99 |
+
async def update_session(self, user_id: int, session: str) -> None:
|
100 |
+
await self.session.update_one(
|
101 |
+
{"user_id": user_id},
|
102 |
+
{"$set": {"session": session, "date": self.get_datetime()}},
|
103 |
+
upsert=True,
|
104 |
+
)
|
105 |
+
|
106 |
+
async def rm_session(self, user_id: int) -> None:
|
107 |
+
await self.session.delete_one({"user_id": user_id})
|
108 |
+
|
109 |
+
async def get_session(self, user_id: int):
|
110 |
+
if not await self.is_session(user_id):
|
111 |
+
return False
|
112 |
+
data = await self.session.find_one({"user_id": user_id})
|
113 |
+
return data
|
114 |
+
|
115 |
+
async def get_all_sessions(self) -> list:
|
116 |
+
return [i async for i in self.session.find({})]
|
117 |
+
|
118 |
+
async def is_gbanned(self, user_id: int) -> bool:
|
119 |
+
if await self.gban.find_one({"user_id": user_id}):
|
120 |
+
return True
|
121 |
+
return False
|
122 |
+
|
123 |
+
async def add_gban(self, user_id: int, reason: str) -> bool:
|
124 |
+
if await self.is_gbanned(user_id):
|
125 |
+
return False
|
126 |
+
await self.gban.insert_one(
|
127 |
+
{"user_id": user_id, "reason": reason, "date": self.get_datetime()}
|
128 |
+
)
|
129 |
+
return True
|
130 |
+
|
131 |
+
async def rm_gban(self, user_id: int):
|
132 |
+
if not await self.is_gbanned(user_id):
|
133 |
+
return None
|
134 |
+
reason = (await self.gban.find_one({"user_id": user_id}))["reason"]
|
135 |
+
await self.gban.delete_one({"user_id": user_id})
|
136 |
+
return reason
|
137 |
+
|
138 |
+
async def get_gban(self) -> list:
|
139 |
+
return [i async for i in self.gban.find({})]
|
140 |
+
|
141 |
+
async def get_gban_user(self, user_id: int) -> dict | None:
|
142 |
+
if not await self.is_gbanned(user_id):
|
143 |
+
return None
|
144 |
+
return await self.gban.find_one({"user_id": user_id})
|
145 |
+
|
146 |
+
async def is_gmuted(self, user_id: int) -> bool:
|
147 |
+
if await self.gmute.find_one({"user_id": user_id}):
|
148 |
+
return True
|
149 |
+
return False
|
150 |
+
|
151 |
+
async def add_gmute(self, user_id: int, reason: str) -> bool:
|
152 |
+
if await self.is_gmuted(user_id):
|
153 |
+
return False
|
154 |
+
await self.gmute.insert_one(
|
155 |
+
{"user_id": user_id, "reason": reason, "date": self.get_datetime()}
|
156 |
+
)
|
157 |
+
return True
|
158 |
+
|
159 |
+
async def rm_gmute(self, user_id: int):
|
160 |
+
if not await self.is_gmuted(user_id):
|
161 |
+
return None
|
162 |
+
reason = (await self.gmute.find_one({"user_id": user_id}))["reason"]
|
163 |
+
await self.gmute.delete_one({"user_id": user_id})
|
164 |
+
return reason
|
165 |
+
|
166 |
+
async def get_gmute(self) -> list:
|
167 |
+
return [i async for i in self.gmute.find({})]
|
168 |
+
|
169 |
+
async def add_mute(self, client: int, user_id: int, chat_id: int, reason: str):
|
170 |
+
await self.mute.update_one(
|
171 |
+
{"client": client, "user_id": user_id, "chat_id": chat_id},
|
172 |
+
{"$set": {"reason": reason, "date": self.get_datetime()}},
|
173 |
+
upsert=True,
|
174 |
+
)
|
175 |
+
|
176 |
+
async def rm_mute(self, client: int, user_id: int, chat_id: int) -> str:
|
177 |
+
reason = (await self.get_mute(client, user_id, chat_id))["reason"]
|
178 |
+
await self.mute.delete_one({"client": client, "user_id": user_id, "chat_id": chat_id})
|
179 |
+
return reason
|
180 |
+
|
181 |
+
async def is_muted(self, client: int, user_id: int, chat_id: int) -> bool:
|
182 |
+
if await self.get_mute(client, user_id, chat_id):
|
183 |
+
return True
|
184 |
+
return False
|
185 |
+
|
186 |
+
async def get_mute(self, client: int, user_id: int, chat_id: int):
|
187 |
+
data = await self.mute.find_one({"client": client, "user_id": user_id, "chat_id": chat_id})
|
188 |
+
return data
|
189 |
+
|
190 |
+
async def set_afk(
|
191 |
+
self, user_id: int, reason: str, media: int, media_type: str
|
192 |
+
) -> None:
|
193 |
+
await self.afk.update_one(
|
194 |
+
{"user_id": user_id},
|
195 |
+
{
|
196 |
+
"$set": {
|
197 |
+
"reason": reason,
|
198 |
+
"time": time.time(),
|
199 |
+
"media": media,
|
200 |
+
"media_type": media_type,
|
201 |
+
}
|
202 |
+
},
|
203 |
+
upsert=True,
|
204 |
+
)
|
205 |
+
|
206 |
+
async def get_afk(self, user_id: int):
|
207 |
+
data = await self.afk.find_one({"user_id": user_id})
|
208 |
+
return data
|
209 |
+
|
210 |
+
async def is_afk(self, user_id: int) -> bool:
|
211 |
+
if await self.afk.find_one({"user_id": user_id}):
|
212 |
+
return True
|
213 |
+
return False
|
214 |
+
|
215 |
+
async def rm_afk(self, user_id: int) -> None:
|
216 |
+
await self.afk.delete_one({"user_id": user_id})
|
217 |
+
|
218 |
+
async def set_flood(self, client_chat: tuple[int, int], settings: dict):
|
219 |
+
await self.antiflood.update_one(
|
220 |
+
{"client": client_chat[0], "chat": client_chat[1]},
|
221 |
+
{"$set": settings},
|
222 |
+
upsert=True,
|
223 |
+
)
|
224 |
+
|
225 |
+
async def get_flood(self, client_chat: tuple[int, int]):
|
226 |
+
data = await self.antiflood.find_one(
|
227 |
+
{"client": client_chat[0], "chat": client_chat[1]}
|
228 |
+
)
|
229 |
+
return data or {}
|
230 |
+
|
231 |
+
async def is_flood(self, client_chat: tuple[int, int]) -> bool:
|
232 |
+
data = await self.get_flood(client_chat)
|
233 |
+
|
234 |
+
if not data:
|
235 |
+
return False
|
236 |
+
|
237 |
+
if data["limit"] == 0:
|
238 |
+
return False
|
239 |
+
|
240 |
+
return True
|
241 |
+
|
242 |
+
async def get_all_floods(self) -> list:
|
243 |
+
return [i async for i in self.antiflood.find({})]
|
244 |
+
|
245 |
+
async def set_autopost(self, client: int, from_channel: int, to_channel: int):
|
246 |
+
await self.autopost.update_one(
|
247 |
+
{"client": client},
|
248 |
+
{
|
249 |
+
"$push": {
|
250 |
+
"autopost": {
|
251 |
+
"from_channel": from_channel,
|
252 |
+
"to_channel": to_channel,
|
253 |
+
"date": self.get_datetime(),
|
254 |
+
}
|
255 |
+
}
|
256 |
+
},
|
257 |
+
upsert=True,
|
258 |
+
)
|
259 |
+
|
260 |
+
async def get_autopost(self, client: int, from_channel: int):
|
261 |
+
data = await self.autopost.find_one(
|
262 |
+
{
|
263 |
+
"client": client,
|
264 |
+
"autopost": {"$elemMatch": {"from_channel": from_channel}},
|
265 |
+
}
|
266 |
+
)
|
267 |
+
return data
|
268 |
+
|
269 |
+
async def is_autopost(
|
270 |
+
self, client: int, from_channel: int, to_channel: int = None
|
271 |
+
) -> bool:
|
272 |
+
if to_channel:
|
273 |
+
data = await self.autopost.find_one(
|
274 |
+
{
|
275 |
+
"client": client,
|
276 |
+
"autopost": {
|
277 |
+
"$elemMatch": {
|
278 |
+
"from_channel": from_channel,
|
279 |
+
"to_channel": to_channel,
|
280 |
+
}
|
281 |
+
},
|
282 |
+
}
|
283 |
+
)
|
284 |
+
else:
|
285 |
+
data = await self.autopost.find_one(
|
286 |
+
{
|
287 |
+
"client": client,
|
288 |
+
"autopost": {"$elemMatch": {"from_channel": from_channel}},
|
289 |
+
}
|
290 |
+
)
|
291 |
+
return True if data else False
|
292 |
+
|
293 |
+
async def rm_autopost(self, client: int, from_channel: int, to_channel: int):
|
294 |
+
await self.autopost.update_one(
|
295 |
+
{"client": client},
|
296 |
+
{
|
297 |
+
"$pull": {
|
298 |
+
"autopost": {
|
299 |
+
"from_channel": from_channel,
|
300 |
+
"to_channel": to_channel,
|
301 |
+
}
|
302 |
+
}
|
303 |
+
},
|
304 |
+
)
|
305 |
+
|
306 |
+
async def get_all_autoposts(self, client: int) -> list:
|
307 |
+
return [i async for i in self.autopost.find({"client": client})]
|
308 |
+
|
309 |
+
async def add_blacklist(self, client: int, chat: int, blacklist: str):
|
310 |
+
await self.blacklist.update_one(
|
311 |
+
{"client": client, "chat": chat},
|
312 |
+
{"$push": {"blacklist": blacklist}},
|
313 |
+
upsert=True,
|
314 |
+
)
|
315 |
+
|
316 |
+
async def rm_blacklist(self, client: int, chat: int, blacklist: str):
|
317 |
+
await self.blacklist.update_one(
|
318 |
+
{"client": client, "chat": chat},
|
319 |
+
{"$pull": {"blacklist": blacklist}},
|
320 |
+
)
|
321 |
+
|
322 |
+
async def is_blacklist(self, client: int, chat: int, blacklist: str) -> bool:
|
323 |
+
blacklists = await self.get_all_blacklists(client, chat)
|
324 |
+
if blacklist in blacklists:
|
325 |
+
return True
|
326 |
+
return False
|
327 |
+
|
328 |
+
async def get_all_blacklists(self, client: int, chat: int) -> list:
|
329 |
+
data = await self.blacklist.find_one({"client": client, "chat": chat})
|
330 |
+
|
331 |
+
if not data:
|
332 |
+
return []
|
333 |
+
|
334 |
+
return data["blacklist"]
|
335 |
+
|
336 |
+
async def get_blacklist_clients(self) -> list:
|
337 |
+
return [i async for i in self.blacklist.find({})]
|
338 |
+
|
339 |
+
async def set_echo(self, client: int, chat: int, user: int):
|
340 |
+
await self.echo.update_one(
|
341 |
+
{"client": client, "chat": chat},
|
342 |
+
{"$push": {"echo": user}},
|
343 |
+
upsert=True,
|
344 |
+
)
|
345 |
+
|
346 |
+
async def rm_echo(self, client: int, chat: int, user: int):
|
347 |
+
await self.echo.update_one(
|
348 |
+
{"client": client, "chat": chat},
|
349 |
+
{"$pull": {"echo": user}},
|
350 |
+
)
|
351 |
+
|
352 |
+
async def is_echo(self, client: int, chat: int, user: int) -> bool:
|
353 |
+
data = await self.get_all_echo(client, chat)
|
354 |
+
if user in data:
|
355 |
+
return True
|
356 |
+
return False
|
357 |
+
|
358 |
+
async def get_all_echo(self, client: int, chat: int) -> list:
|
359 |
+
data = await self.echo.find_one({"client": client, "chat": chat})
|
360 |
+
|
361 |
+
if not data:
|
362 |
+
return []
|
363 |
+
|
364 |
+
return data["echo"]
|
365 |
+
|
366 |
+
async def set_filter(self, client: int, chat: int, keyword: str, msgid: int):
|
367 |
+
await self.filter.update_one(
|
368 |
+
{"client": client, "chat": chat},
|
369 |
+
{"$push": {"filter": {"keyword": keyword, "msgid": msgid}}},
|
370 |
+
upsert=True,
|
371 |
+
)
|
372 |
+
|
373 |
+
async def rm_filter(self, client: int, chat: int, keyword: str):
|
374 |
+
await self.filter.update_one(
|
375 |
+
{"client": client, "chat": chat},
|
376 |
+
{"$pull": {"filter": {"keyword": keyword}}},
|
377 |
+
)
|
378 |
+
|
379 |
+
async def rm_all_filters(self, client: int, chat: int):
|
380 |
+
await self.filter.delete_one({"client": client, "chat": chat})
|
381 |
+
|
382 |
+
async def is_filter(self, client: int, chat: int, keyword: str) -> bool:
|
383 |
+
data = await self.get_filter(client, chat, keyword)
|
384 |
+
return True if data else False
|
385 |
+
|
386 |
+
async def get_filter(self, client: int, chat: int, keyword: str):
|
387 |
+
data = await self.filter.find_one(
|
388 |
+
{
|
389 |
+
"client": client,
|
390 |
+
"chat": chat,
|
391 |
+
"filter": {"$elemMatch": {"keyword": keyword}},
|
392 |
+
}
|
393 |
+
)
|
394 |
+
return data
|
395 |
+
|
396 |
+
async def get_all_filters(self, client: int, chat: int) -> list:
|
397 |
+
data = await self.filter.find_one({"client": client, "chat": chat})
|
398 |
+
|
399 |
+
if not data:
|
400 |
+
return []
|
401 |
+
|
402 |
+
return data["filter"]
|
403 |
+
|
404 |
+
async def set_snip(self, client: int, chat: int, keyword: str, msgid: int):
|
405 |
+
await self.snips.update_one(
|
406 |
+
{"client": client, "chat": chat},
|
407 |
+
{"$push": {"snips": {"keyword": keyword, "msgid": msgid}}},
|
408 |
+
upsert=True,
|
409 |
+
)
|
410 |
+
|
411 |
+
async def rm_snip(self, client: int, chat: int, keyword: str):
|
412 |
+
await self.snips.update_one(
|
413 |
+
{"client": client, "chat": chat},
|
414 |
+
{"$pull": {"snips": {"keyword": keyword}}},
|
415 |
+
)
|
416 |
+
|
417 |
+
async def rm_all_snips(self, client: int, chat: int):
|
418 |
+
await self.snips.delete_one({"client": client, "chat": chat})
|
419 |
+
|
420 |
+
async def is_snip(self, client: int, chat: int, keyword: str) -> bool:
|
421 |
+
data = await self.get_snip(client, chat, keyword)
|
422 |
+
return True if data else False
|
423 |
+
|
424 |
+
async def get_snip(self, client: int, chat: int, keyword: str):
|
425 |
+
data = await self.snips.find_one(
|
426 |
+
{
|
427 |
+
"client": client,
|
428 |
+
"chat": chat,
|
429 |
+
"snips": {"$elemMatch": {"keyword": keyword}},
|
430 |
+
}
|
431 |
+
)
|
432 |
+
return data
|
433 |
+
|
434 |
+
async def get_all_snips(self, client: int, chat: int) -> list:
|
435 |
+
data = await self.snips.find_one({"client": client, "chat": chat})
|
436 |
+
|
437 |
+
if not data:
|
438 |
+
return []
|
439 |
+
|
440 |
+
return data["snips"]
|
441 |
+
|
442 |
+
async def add_pmpermit(self, client: int, user: int):
|
443 |
+
await self.pmpermit.update_one(
|
444 |
+
{"client": client, "user": user},
|
445 |
+
{"$set": {"date": self.get_datetime()}},
|
446 |
+
upsert=True,
|
447 |
+
)
|
448 |
+
|
449 |
+
async def rm_pmpermit(self, client: int, user: int):
|
450 |
+
await self.pmpermit.delete_one({"client": client, "user": user})
|
451 |
+
|
452 |
+
async def is_pmpermit(self, client: int, user: int) -> bool:
|
453 |
+
data = await self.get_pmpermit(client, user)
|
454 |
+
return True if data else False
|
455 |
+
|
456 |
+
async def get_pmpermit(self, client: int, user: int):
|
457 |
+
data = await self.pmpermit.find_one({"client": client, "user": user})
|
458 |
+
return data
|
459 |
+
|
460 |
+
async def get_all_pmpermits(self, client: int) -> list:
|
461 |
+
return [i async for i in self.pmpermit.find({"client": client})]
|
462 |
+
|
463 |
+
async def set_welcome(self, client: int, chat: int, message: int):
|
464 |
+
await self.greetings.update_one(
|
465 |
+
{"client": client, "chat": chat, "welcome": True},
|
466 |
+
{"$set": {"message": message}},
|
467 |
+
upsert=True,
|
468 |
+
)
|
469 |
+
|
470 |
+
async def rm_welcome(self, client: int, chat: int):
|
471 |
+
await self.greetings.delete_one(
|
472 |
+
{"client": client, "chat": chat, "welcome": True}
|
473 |
+
)
|
474 |
+
|
475 |
+
async def is_welcome(self, client: int, chat: int) -> bool:
|
476 |
+
data = await self.get_welcome(client, chat)
|
477 |
+
return True if data else False
|
478 |
+
|
479 |
+
async def get_welcome(self, client: int, chat: int):
|
480 |
+
data = await self.greetings.find_one(
|
481 |
+
{"client": client, "chat": chat, "welcome": True}
|
482 |
+
)
|
483 |
+
return data
|
484 |
+
|
485 |
+
async def set_goodbye(self, client: int, chat: int, message: int):
|
486 |
+
await self.greetings.update_one(
|
487 |
+
{"client": client, "chat": chat, "welcome": False},
|
488 |
+
{"$set": {"message": message}},
|
489 |
+
upsert=True,
|
490 |
+
)
|
491 |
+
|
492 |
+
async def rm_goodbye(self, client: int, chat: int):
|
493 |
+
await self.greetings.delete_one(
|
494 |
+
{"client": client, "chat": chat, "welcome": False}
|
495 |
+
)
|
496 |
+
|
497 |
+
async def is_goodbye(self, client: int, chat: int) -> bool:
|
498 |
+
data = await self.get_goodbye(client, chat)
|
499 |
+
return True if data else False
|
500 |
+
|
501 |
+
async def get_goodbye(self, client: int, chat: int):
|
502 |
+
data = await self.greetings.find_one(
|
503 |
+
{"client": client, "chat": chat, "welcome": False}
|
504 |
+
)
|
505 |
+
return data
|
506 |
+
|
507 |
+
async def get_all_greetings(self, client: int) -> list:
|
508 |
+
return [i async for i in self.greetings.find({"client": client})]
|
509 |
+
|
510 |
+
async def add_forcesub(self, chat: int, must_join: int):
|
511 |
+
await self.forcesub.update_one(
|
512 |
+
{"chat": chat},
|
513 |
+
{"$push": {"must_join": must_join}},
|
514 |
+
upsert=True,
|
515 |
+
)
|
516 |
+
|
517 |
+
async def rm_forcesub(self, chat: int, must_join: int) -> int:
|
518 |
+
await self.forcesub.update_one(
|
519 |
+
{"chat": chat},
|
520 |
+
{"$pull": {"must_join": must_join}},
|
521 |
+
)
|
522 |
+
data = await self.forcesub.find_one({"chat": chat})
|
523 |
+
return len(data["must_join"])
|
524 |
+
|
525 |
+
async def rm_all_forcesub(self, in_chat: int):
|
526 |
+
await self.forcesub.delete_one({"chat": in_chat})
|
527 |
+
|
528 |
+
async def is_forcesub(self, chat: int, must_join: int) -> bool:
|
529 |
+
data = await self.get_forcesub(chat)
|
530 |
+
if must_join in data["must_join"]:
|
531 |
+
return True
|
532 |
+
return False
|
533 |
+
|
534 |
+
async def get_forcesub(self, in_chat: int):
|
535 |
+
data = await self.forcesub.find_one({"chat": in_chat})
|
536 |
+
return data
|
537 |
+
|
538 |
+
async def get_all_forcesubs(self) -> list:
|
539 |
+
return [i async for i in self.forcesub.find({})]
|
540 |
+
|
541 |
+
async def add_gachabot(
|
542 |
+
self, client: int, bot: tuple[int, str], catch_command: str, chat_id: int
|
543 |
+
):
|
544 |
+
await self.gachabots.update_one(
|
545 |
+
{"client": client, "bot": bot[0]},
|
546 |
+
{
|
547 |
+
"$set": {
|
548 |
+
"username": bot[1],
|
549 |
+
"catch_command": catch_command,
|
550 |
+
"chat_id": chat_id,
|
551 |
+
"date": self.get_datetime(),
|
552 |
+
}
|
553 |
+
},
|
554 |
+
upsert=True,
|
555 |
+
)
|
556 |
+
|
557 |
+
async def rm_gachabot(self, client: int, bot: int, chat_id: int = None):
|
558 |
+
if chat_id:
|
559 |
+
await self.gachabots.delete_one(
|
560 |
+
{"client": client, "bot": bot, "chat_id": chat_id}
|
561 |
+
)
|
562 |
+
else:
|
563 |
+
await self.gachabots.delete_one({"client": client, "bot": bot})
|
564 |
+
|
565 |
+
async def is_gachabot(self, client: int, bot: int, chat_id: int) -> bool:
|
566 |
+
data = await self.get_gachabot(client, bot, chat_id)
|
567 |
+
return True if data else False
|
568 |
+
|
569 |
+
async def get_gachabot(self, client: int, bot: int, chat_id: int):
|
570 |
+
data = await self.gachabots.find_one(
|
571 |
+
{"client": client, "bot": bot, "chat_id": chat_id}
|
572 |
+
)
|
573 |
+
|
574 |
+
return data
|
575 |
+
|
576 |
+
async def get_all_gachabots(self, client: int) -> list:
|
577 |
+
return [i async for i in self.gachabots.find({"client": client})]
|
578 |
+
|
579 |
+
async def get_all_gachabots_id(self) -> list:
|
580 |
+
data = await self.gachabots.distinct("bot")
|
581 |
+
return data
|
582 |
+
|
583 |
+
|
584 |
+
db = Database(Config.DATABASE_URL)
|
Hellbot/core/initializer.py
ADDED
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
from .clients import hellbot
|
3 |
+
from .config import Config, Symbols
|
4 |
+
from .database import db
|
5 |
+
from .logger import LOGS
|
6 |
+
|
7 |
+
|
8 |
+
async def _AuthUsers() -> None:
|
9 |
+
temp_list = []
|
10 |
+
temp_list.append(Config.OWNER_ID)
|
11 |
+
temp_list.extend([(await client.get_me()).id for client in hellbot.users])
|
12 |
+
|
13 |
+
stan_users = await db.get_all_stans()
|
14 |
+
for user in stan_users:
|
15 |
+
temp_list.append(user["user_id"])
|
16 |
+
|
17 |
+
users = list(set(temp_list))
|
18 |
+
for user in users:
|
19 |
+
Config.AUTH_USERS.add(user)
|
20 |
+
|
21 |
+
temp_list = None
|
22 |
+
LOGS.info(
|
23 |
+
f"{Symbols.arrow_right * 2} Added Authorized Users {Symbols.arrow_left * 2}"
|
24 |
+
)
|
25 |
+
|
26 |
+
|
27 |
+
async def _StanUsers() -> None:
|
28 |
+
users = await db.get_all_stans()
|
29 |
+
for user in users:
|
30 |
+
Config.STAN_USERS.add(user["user_id"])
|
31 |
+
|
32 |
+
LOGS.info(f"{Symbols.arrow_right * 2} Added Stan Users {Symbols.arrow_left * 2}")
|
33 |
+
|
34 |
+
|
35 |
+
async def _GbanUsers() -> None:
|
36 |
+
users = await db.get_gban()
|
37 |
+
for user in users:
|
38 |
+
Config.BANNED_USERS.add(user["user_id"])
|
39 |
+
|
40 |
+
LOGS.info(
|
41 |
+
f"{Symbols.arrow_right * 2} Added {len(users)} Gbanned Users {Symbols.arrow_left * 2}"
|
42 |
+
)
|
43 |
+
|
44 |
+
musers = await db.get_gmute()
|
45 |
+
for user in musers:
|
46 |
+
Config.MUTED_USERS.add(user["user_id"])
|
47 |
+
|
48 |
+
LOGS.info(
|
49 |
+
f"{Symbols.arrow_right * 2} Added {len(musers)} Gmuted Users {Symbols.arrow_left * 2}"
|
50 |
+
)
|
51 |
+
|
52 |
+
|
53 |
+
async def UserSetup() -> None:
|
54 |
+
"""Initialize Users Config"""
|
55 |
+
LOGS.info(f"{Symbols.bullet * 3} Setting Up Users {Symbols.bullet * 3}")
|
56 |
+
await _AuthUsers()
|
57 |
+
await _StanUsers()
|
58 |
+
await _GbanUsers()
|
59 |
+
|
60 |
+
|
61 |
+
async def ForcesubSetup() -> None:
|
62 |
+
"""Initialize Forcesub Config"""
|
63 |
+
chats = await db.get_all_forcesubs()
|
64 |
+
for chat in chats:
|
65 |
+
if chat not in Config.FORCESUBS:
|
66 |
+
Config.FORCESUBS.add(chat["chat"])
|
67 |
+
|
68 |
+
|
69 |
+
async def GachaBotsSetup() -> None:
|
70 |
+
"""Initialize GachaBots Config"""
|
71 |
+
bots = await db.get_all_gachabots_id()
|
72 |
+
for bot in bots:
|
73 |
+
Config.GACHA_BOTS.add(bot)
|
74 |
+
|
75 |
+
|
76 |
+
async def TemplateSetup() -> None:
|
77 |
+
"""Initialize Templates Config"""
|
78 |
+
module_name = "temp_module"
|
79 |
+
module = sys.modules.get(module_name)
|
80 |
+
if module is None:
|
81 |
+
module = type(sys)(module_name)
|
82 |
+
|
83 |
+
with open("Hellbot/functions/templates.py", "r", encoding="utf-8") as file:
|
84 |
+
exec(file.read(), module.__dict__)
|
85 |
+
|
86 |
+
global_vars = module.__dict__
|
87 |
+
|
88 |
+
var_n_value: dict[str, str] = {
|
89 |
+
var_name: global_vars[var_name][0]
|
90 |
+
for var_name in global_vars
|
91 |
+
if var_name.isupper() and not callable(global_vars[var_name])
|
92 |
+
}
|
93 |
+
|
94 |
+
Config.TEMPLATES = var_n_value
|
Hellbot/core/logger.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
from logging.handlers import RotatingFileHandler
|
3 |
+
|
4 |
+
logging.basicConfig(
|
5 |
+
format="[%(asctime)s]:[%(name)s]:[%(levelname)s] - %(message)s",
|
6 |
+
level=logging.INFO,
|
7 |
+
datefmt="%H:%M:%S",
|
8 |
+
handlers=[
|
9 |
+
RotatingFileHandler(
|
10 |
+
"HellBot.log", maxBytes=(1024 * 1024 * 5), backupCount=10, encoding="utf-8"
|
11 |
+
),
|
12 |
+
logging.StreamHandler(),
|
13 |
+
],
|
14 |
+
)
|
15 |
+
|
16 |
+
|
17 |
+
logging.getLogger("pyrogram").setLevel(logging.ERROR)
|
18 |
+
|
19 |
+
LOGS = logging.getLogger("HellBot")
|
Hellbot/functions/__init__.py
ADDED
File without changes
|
Hellbot/functions/admins.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyrogram.enums import ChatMembersFilter, ChatMemberStatus, ChatType
|
2 |
+
from pyrogram.types import Chat
|
3 |
+
|
4 |
+
from Hellbot.core import hellbot
|
5 |
+
|
6 |
+
|
7 |
+
async def get_admins(chat_id: int) -> list:
|
8 |
+
admins = []
|
9 |
+
async for x in hellbot.bot.get_chat_members(
|
10 |
+
chat_id, filter=ChatMembersFilter.ADMINISTRATORS
|
11 |
+
):
|
12 |
+
admins.append(x.user.id)
|
13 |
+
return admins
|
14 |
+
|
15 |
+
|
16 |
+
async def is_user_admin(chat: Chat, user_id: int) -> bool:
|
17 |
+
if chat.type in [ChatType.PRIVATE, ChatType.BOT]:
|
18 |
+
return True
|
19 |
+
|
20 |
+
status = (await chat.get_member(user_id)).status
|
21 |
+
if status in [ChatMemberStatus.OWNER, ChatMemberStatus.ADMINISTRATOR]:
|
22 |
+
return True
|
23 |
+
|
24 |
+
return False
|
Hellbot/functions/convert.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
|
4 |
+
from pyrogram.types import Message
|
5 |
+
from PIL import Image
|
6 |
+
from Hellbot.core import Config
|
7 |
+
|
8 |
+
from .tools import runcmd
|
9 |
+
|
10 |
+
|
11 |
+
async def convert_to_gif(file: str, is_video: bool = False) -> str:
|
12 |
+
resultFileName = f"gif_{round(time.time())}.mp4"
|
13 |
+
|
14 |
+
if is_video:
|
15 |
+
cmd = f"ffmpeg -i '{file}' -c copy '{resultFileName}'"
|
16 |
+
else:
|
17 |
+
cmd = f"lottie_convert.py '{file}' '{resultFileName}'"
|
18 |
+
|
19 |
+
await runcmd(cmd)
|
20 |
+
|
21 |
+
return resultFileName
|
22 |
+
|
23 |
+
|
24 |
+
async def tgs_to_png(file: str) -> str:
|
25 |
+
resultFileName = f"png_{round(time.time())}.png"
|
26 |
+
|
27 |
+
cmd = f"lottie_convert.py '{file}' '{resultFileName}'"
|
28 |
+
|
29 |
+
await runcmd(cmd)
|
30 |
+
|
31 |
+
return resultFileName
|
32 |
+
|
33 |
+
|
34 |
+
async def image_to_sticker(file: str, max_size: tuple = (512, 512)) -> tuple[bool, str]:
|
35 |
+
try:
|
36 |
+
with Image.open(file) as img:
|
37 |
+
original_width, original_height = img.size
|
38 |
+
|
39 |
+
new_width = min(original_width, max_size[0])
|
40 |
+
new_height = min(original_height, max_size[1])
|
41 |
+
|
42 |
+
if original_width > max_size[0] or original_height > max_size[1]:
|
43 |
+
img = img.resize((new_width, new_height), Image.LANCZOS)
|
44 |
+
|
45 |
+
file_name = f"sticker_{int(time.time())}.png"
|
46 |
+
img.save(file_name, "PNG")
|
47 |
+
|
48 |
+
return True, file_name
|
49 |
+
|
50 |
+
except Exception as e:
|
51 |
+
return False, str(e)
|
52 |
+
|
53 |
+
|
54 |
+
async def video_to_png(
|
55 |
+
file: str, duration: float, output: str = None
|
56 |
+
) -> tuple[str, bool]:
|
57 |
+
resultFileName = output or f"{os.path.basename(file)}.png"
|
58 |
+
cut_at = duration // 2
|
59 |
+
|
60 |
+
cmd = f"ffmpeg -ss {cut_at} -i '{file}' -vframes 1 '{resultFileName}'"
|
61 |
+
|
62 |
+
_, err, _, _ = await runcmd(cmd)
|
63 |
+
if err:
|
64 |
+
return err, False
|
65 |
+
|
66 |
+
return resultFileName, True
|
67 |
+
|
68 |
+
|
69 |
+
async def video_to_sticker(file: Message) -> tuple[str, bool]:
|
70 |
+
try:
|
71 |
+
if file.animation:
|
72 |
+
width, height = file.animation.width, file.animation.height
|
73 |
+
elif file.video:
|
74 |
+
width, height = file.video.width, file.video.height
|
75 |
+
else:
|
76 |
+
return "Unsupported media type.", False
|
77 |
+
|
78 |
+
file_path = await file.download(Config.TEMP_DIR)
|
79 |
+
output_path = os.path.join(Config.TEMP_DIR, "videoSticker.webm")
|
80 |
+
|
81 |
+
if height > width:
|
82 |
+
scale_params = f"scale=-1:512"
|
83 |
+
else:
|
84 |
+
scale_params = f"scale=512:-1"
|
85 |
+
|
86 |
+
cmd = (
|
87 |
+
f"ffmpeg -i {file_path} "
|
88 |
+
f"-vf fps=30,{scale_params} -t 3 -c:v libvpx-vp9 -b:v 256k -an -pix_fmt yuv420p -auto-alt-ref 0 -loop 0 "
|
89 |
+
f"-f webm {output_path}"
|
90 |
+
)
|
91 |
+
|
92 |
+
await runcmd(cmd)
|
93 |
+
os.remove(file_path)
|
94 |
+
|
95 |
+
return output_path, True
|
96 |
+
|
97 |
+
except Exception as e:
|
98 |
+
return f"Error during conversion: {e}", False
|
Hellbot/functions/driver.py
ADDED
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|