From 5688edc22f004c872944d9b331e57f866ed334d2 Mon Sep 17 00:00:00 2001
From: Abhi <85984486+AbhiTheModder@users.noreply.github.com>
Date: Mon, 25 Nov 2024 03:55:37 +0530
Subject: [PATCH] black
---
app.py | 5 +--
install.py | 2 +-
modules/aiutils.py | 76 ++++++++++++++++++++++++++++++++++------------
modules/help.py | 12 ++++++--
modules/loader.py | 5 ++-
modules/open.py | 1 -
modules/updater.py | 2 +-
modules/upl.py | 10 ++----
utils/config.py | 4 ++-
utils/handlers.py | 5 +--
utils/lexicapi.py | 18 +++++------
11 files changed, 91 insertions(+), 49 deletions(-)
diff --git a/app.py b/app.py
index 08abe22..d70930e 100644
--- a/app.py
+++ b/app.py
@@ -1,10 +1,11 @@
from flask import Flask
+
app = Flask(__name__)
-@app.route('/')
+@app.route("/")
def hello_world():
- return 'This is Moon'
+ return "This is Moon"
if __name__ == "__main__":
diff --git a/install.py b/install.py
index 115f7cc..84ee768 100644
--- a/install.py
+++ b/install.py
@@ -63,7 +63,7 @@ if __name__ == "__main__":
"Custom modules: @moonub_modules\n"
"Chat: @moonub_chat\n"
f"For restart, enter:\n"
- f"{restart}"
+ f"{restart}",
)
except Exception as e:
print(f"[ERROR]: Sending Message to me failed! {e}")
diff --git a/modules/aiutils.py b/modules/aiutils.py
index 727fb4a..1abf74b 100644
--- a/modules/aiutils.py
+++ b/modules/aiutils.py
@@ -108,7 +108,9 @@ async def vdxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -181,9 +183,13 @@ async def vdxl(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
@@ -240,7 +246,9 @@ async def vdxl2(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -313,9 +321,13 @@ async def vdxl2(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
@@ -372,7 +384,9 @@ async def vdxl3(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -445,9 +459,13 @@ async def vdxl3(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
@@ -504,7 +522,9 @@ async def vfxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -581,9 +601,13 @@ async def vfxl(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
@@ -640,7 +664,9 @@ async def vpxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -717,9 +743,13 @@ async def vpxl(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
@@ -776,7 +806,9 @@ async def vpixl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -912,7 +944,9 @@ async def vkxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file:
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
+ image_data = base64.b64encode(image_file.read()).decode(
+ "utf-8"
+ )
img2img = True
model_found = True
break
@@ -985,9 +1019,13 @@ async def vkxl(c: Client, message: Message):
try:
details = response["detail"]
mes = response["message"]
- return await message.edit_text(f"{details}: {mes}")
+ return await message.edit_text(
+ f"{details}: {mes}"
+ )
except KeyError:
- return await message.edit_text("An Error Occurred, please try again later")
+ return await message.edit_text(
+ "An Error Occurred, please try again later"
+ )
except MessageTooLong:
await message.edit_text(
diff --git a/modules/help.py b/modules/help.py
index bbaa29c..a0edcbb 100644
--- a/modules/help.py
+++ b/modules/help.py
@@ -20,6 +20,7 @@ from utils.scripts import format_module_help, with_reply
current_page = 0
total_pages = 0
+
async def send_page(message, module_list, page, total_pages):
start_index = (page - 1) * 10
end_index = start_index + 10
@@ -63,6 +64,7 @@ async def help_cmd(_, message: Message):
if not module_found:
await message.edit(f"Module or command {command_name} not found")
+
@Client.on_message(filters.command(["pn", "pp", "pq"], prefix) & filters.me)
@with_reply
async def handle_navigation(_, message: Message):
@@ -71,14 +73,18 @@ async def handle_navigation(_, message: Message):
if message.command[0].lower() == "pn":
if current_page < total_pages:
current_page += 1
- await send_page(message, list(modules_help.keys()), current_page, total_pages)
+ await send_page(
+ message, list(modules_help.keys()), current_page, total_pages
+ )
return await message.reply_to_message.delete()
else:
await message.edit("No more pages available.")
elif message.command[0].lower() == "pp":
if current_page > 1:
current_page -= 1
- await send_page(message, list(modules_help.keys()), current_page, total_pages)
+ await send_page(
+ message, list(modules_help.keys()), current_page, total_pages
+ )
return await message.reply_to_message.delete()
else:
return await message.edit("This is the first page.")
@@ -91,4 +97,4 @@ modules_help["help"] = {
"help [module/command name]": "Get common/module/command help",
"pn/pp/pq": "Navigate through help pages"
+ " (pn: next page, pp: previous page, pq: quit help)",
- }
+}
diff --git a/modules/loader.py b/modules/loader.py
index 8983bb2..7c5ad3b 100644
--- a/modules/loader.py
+++ b/modules/loader.py
@@ -146,7 +146,10 @@ async def unload_mods(_, message: Message):
if os.path.exists(f"{BASE_PATH}/modules/custom_modules/{module_name}.py"):
os.remove(f"{BASE_PATH}/modules/custom_modules/{module_name}.py")
if module_name == "musicbot":
- subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y", "requirements.txt"], cwd=f"{BASE_PATH}/musicbot")
+ subprocess.run(
+ [sys.executable, "-m", "pip", "uninstall", "-y", "requirements.txt"],
+ cwd=f"{BASE_PATH}/musicbot",
+ )
shutil.rmtree(f"{BASE_PATH}/musicbot")
await message.edit(f"The module {module_name} removed!")
restart()
diff --git a/modules/open.py b/modules/open.py
index 4a2fe70..3dc90d5 100644
--- a/modules/open.py
+++ b/modules/open.py
@@ -67,7 +67,6 @@ def check_extension(file_path):
return extensions.get(ext, "
")
-
@Client.on_message(filters.command("open", prefix) & filters.me)
async def openfile(client: Client, message: Message):
if not message.reply_to_message:
diff --git a/modules/updater.py b/modules/updater.py
index 0c37caa..c48f8db 100644
--- a/modules/updater.py
+++ b/modules/updater.py
@@ -73,7 +73,7 @@ async def update(_, message: Message):
await message.edit("Updating...")
try:
- if not check_command('termux-setup-storage'):
+ if not check_command("termux-setup-storage"):
subprocess.run(
[sys.executable, "-m", "pip", "install", "-U", "pip"], check=True
)
diff --git a/modules/upl.py b/modules/upl.py
index 6a78ed4..285aff6 100644
--- a/modules/upl.py
+++ b/modules/upl.py
@@ -56,9 +56,7 @@ async def dlf(client: Client, message: Message):
await client.download_media(message.reply_to_message)
await message.edit("Downloaded Successfully!")
else:
- await message.edit(
- f"Usage: {prefix}dlf [reply to a file]"
- )
+ await message.edit(f"Usage: {prefix}dlf [reply to a file]")
@Client.on_message(filters.command("moonlogs", prefix) & filters.me)
@@ -69,9 +67,7 @@ async def mupl(client: Client, message: Message):
await message.edit("Uploading Now...")
await client.send_document(message.chat.id, link)
await message.delete()
- return await message.edit(
- "Error: LOGS file doesn't exist."
- )
+ return await message.edit("Error: LOGS file doesn't exist.")
except Exception as e:
await message.edit(format_exc(e))
@@ -110,5 +106,5 @@ modules_help["uplud"] = {
"upl [filepath]/[reply to path]*": "Upload a file from your local machine to Telegram",
"dlf": "Download a file from Telegram to your local machine",
"uplr [filepath]/[reply to path]*": "Upload a file from your local machine to Telegram, delete the file after uploading",
- "moonlogs": "Upload the moonlogs.txt file to Telegram"
+ "moonlogs": "Upload the moonlogs.txt file to Telegram",
}
diff --git a/utils/config.py b/utils/config.py
index cb96fdd..d14ebe2 100644
--- a/utils/config.py
+++ b/utils/config.py
@@ -28,4 +28,6 @@ cohere_key = os.getenv("COHERE_KEY", env.str("COHERE_KEY", ""))
pm_limit = int(os.getenv("PM_LIMIT", env.int("PM_LIMIT", 4)))
test_server = bool(os.getenv("TEST_SERVER", env.bool("TEST_SERVER", False)))
-modules_repo_branch = os.getenv("MODULES_REPO_BRANCH", env.str("MODULES_REPO_BRANCH", "master"))
+modules_repo_branch = os.getenv(
+ "MODULES_REPO_BRANCH", env.str("MODULES_REPO_BRANCH", "master")
+)
diff --git a/utils/handlers.py b/utils/handlers.py
index d42d822..f5da869 100644
--- a/utils/handlers.py
+++ b/utils/handlers.py
@@ -908,10 +908,7 @@ class PromoteHandler:
user_id,
privileges=ChatPrivileges(**self.common_privileges_promote),
)
- if (
- len(self.cause.split()) > 1
- and self.message.chat.type == "group"
- ):
+ if len(self.cause.split()) > 1 and self.message.chat.type == "group":
await self.client.set_administrator_title(
self.chat_id,
user_id,
diff --git a/utils/lexicapi.py b/utils/lexicapi.py
index 31cec51..d3a7493 100644
--- a/utils/lexicapi.py
+++ b/utils/lexicapi.py
@@ -5,11 +5,11 @@ from lexica import AsyncClient, Client
def ImageModels():
- models = Client().models['models']['image']
+ models = Client().models["models"]["image"]
dict_models = {}
for model in models:
- model_id = model['id']
- model_name = model['name']
+ model_id = model["id"]
+ model_name = model["name"]
dict_models[model_name] = model_id
return dict_models
@@ -17,18 +17,18 @@ def ImageModels():
async def ImageGeneration(model, prompt):
try:
output = await AsyncClient().generate(model, prompt, "")
- if output['code'] != 1:
+ if output["code"] != 1:
return 2
- if output['code'] == 69:
- return output['code']
- task_id, request_id = output['task_id'], output['request_id']
+ if output["code"] == 69:
+ return output["code"]
+ task_id, request_id = output["task_id"], output["request_id"]
await asyncio.sleep(20)
tries = 0
image_url = None
resp = await AsyncClient().getImages(task_id, request_id)
while True:
- if resp['code'] == 2:
- image_url = resp['img_urls']
+ if resp["code"] == 2:
+ image_url = resp["img_urls"]
break
if tries > 15:
break