This commit is contained in:
Abhi
2024-11-25 03:55:37 +05:30
parent 1fc0237af4
commit 5688edc22f
11 changed files with 91 additions and 49 deletions

5
app.py
View File

@@ -1,10 +1,11 @@
from flask import Flask from flask import Flask
app = Flask(__name__) app = Flask(__name__)
@app.route('/') @app.route("/")
def hello_world(): def hello_world():
return 'This is Moon' return "This is Moon"
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -63,7 +63,7 @@ if __name__ == "__main__":
"Custom modules: @moonub_modules\n" "Custom modules: @moonub_modules\n"
"Chat: @moonub_chat\n" "Chat: @moonub_chat\n"
f"For restart, enter:</b>\n" f"For restart, enter:</b>\n"
f"<code>{restart}</code>" f"<code>{restart}</code>",
) )
except Exception as e: except Exception as e:
print(f"[ERROR]: Sending Message to me failed! {e}") print(f"[ERROR]: Sending Message to me failed! {e}")

View File

@@ -108,7 +108,9 @@ async def vdxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -181,9 +183,13 @@ async def vdxl(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( 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() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -313,9 +321,13 @@ async def vdxl2(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( 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() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -445,9 +459,13 @@ async def vdxl3(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( 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() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -581,9 +601,13 @@ async def vfxl(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( 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() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -717,9 +743,13 @@ async def vpxl(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( 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() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -912,7 +944,9 @@ async def vkxl(c: Client, message: Message):
prompt = message.reply_to_message.caption[len(f"{m}") :].strip() prompt = message.reply_to_message.caption[len(f"{m}") :].strip()
image_path = await message.reply_to_message.download() image_path = await message.reply_to_message.download()
with open(image_path, "rb") as image_file: 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 img2img = True
model_found = True model_found = True
break break
@@ -985,9 +1019,13 @@ async def vkxl(c: Client, message: Message):
try: try:
details = response["detail"] details = response["detail"]
mes = response["message"] mes = response["message"]
return await message.edit_text(f"<b>{details}: </b><code>{mes}</code>") return await message.edit_text(
f"<b>{details}: </b><code>{mes}</code>"
)
except KeyError: 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: except MessageTooLong:
await message.edit_text( await message.edit_text(

View File

@@ -20,6 +20,7 @@ from utils.scripts import format_module_help, with_reply
current_page = 0 current_page = 0
total_pages = 0 total_pages = 0
async def send_page(message, module_list, page, total_pages): async def send_page(message, module_list, page, total_pages):
start_index = (page - 1) * 10 start_index = (page - 1) * 10
end_index = start_index + 10 end_index = start_index + 10
@@ -63,6 +64,7 @@ async def help_cmd(_, message: Message):
if not module_found: if not module_found:
await message.edit(f"<b>Module or command {command_name} not found</b>") await message.edit(f"<b>Module or command {command_name} not found</b>")
@Client.on_message(filters.command(["pn", "pp", "pq"], prefix) & filters.me) @Client.on_message(filters.command(["pn", "pp", "pq"], prefix) & filters.me)
@with_reply @with_reply
async def handle_navigation(_, message: Message): async def handle_navigation(_, message: Message):
@@ -71,14 +73,18 @@ async def handle_navigation(_, message: Message):
if message.command[0].lower() == "pn": if message.command[0].lower() == "pn":
if current_page < total_pages: if current_page < total_pages:
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() return await message.reply_to_message.delete()
else: else:
await message.edit("No more pages available.") await message.edit("No more pages available.")
elif message.command[0].lower() == "pp": elif message.command[0].lower() == "pp":
if current_page > 1: if current_page > 1:
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() return await message.reply_to_message.delete()
else: else:
return await message.edit("This is the first page.") 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", "help [module/command name]": "Get common/module/command help",
"pn/pp/pq": "Navigate through help pages" "pn/pp/pq": "Navigate through help pages"
+ " (pn: next page, pp: previous page, pq: quit help)", + " (pn: next page, pp: previous page, pq: quit help)",
} }

View File

@@ -146,7 +146,10 @@ async def unload_mods(_, message: Message):
if os.path.exists(f"{BASE_PATH}/modules/custom_modules/{module_name}.py"): if os.path.exists(f"{BASE_PATH}/modules/custom_modules/{module_name}.py"):
os.remove(f"{BASE_PATH}/modules/custom_modules/{module_name}.py") os.remove(f"{BASE_PATH}/modules/custom_modules/{module_name}.py")
if module_name == "musicbot": 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") shutil.rmtree(f"{BASE_PATH}/musicbot")
await message.edit(f"<b>The module <code>{module_name}</code> removed!</b>") await message.edit(f"<b>The module <code>{module_name}</code> removed!</b>")
restart() restart()

View File

@@ -67,7 +67,6 @@ def check_extension(file_path):
return extensions.get(ext, "<pre>") return extensions.get(ext, "<pre>")
@Client.on_message(filters.command("open", prefix) & filters.me) @Client.on_message(filters.command("open", prefix) & filters.me)
async def openfile(client: Client, message: Message): async def openfile(client: Client, message: Message):
if not message.reply_to_message: if not message.reply_to_message:

View File

@@ -73,7 +73,7 @@ async def update(_, message: Message):
await message.edit("<b>Updating...</b>") await message.edit("<b>Updating...</b>")
try: try:
if not check_command('termux-setup-storage'): if not check_command("termux-setup-storage"):
subprocess.run( subprocess.run(
[sys.executable, "-m", "pip", "install", "-U", "pip"], check=True [sys.executable, "-m", "pip", "install", "-U", "pip"], check=True
) )

View File

@@ -56,9 +56,7 @@ async def dlf(client: Client, message: Message):
await client.download_media(message.reply_to_message) await client.download_media(message.reply_to_message)
await message.edit("<b>Downloaded Successfully!</b>") await message.edit("<b>Downloaded Successfully!</b>")
else: else:
await message.edit( await message.edit(f"<b>Usage: </b><code>{prefix}dlf [reply to a file]</code>")
f"<b>Usage: </b><code>{prefix}dlf [reply to a file]</code>"
)
@Client.on_message(filters.command("moonlogs", prefix) & filters.me) @Client.on_message(filters.command("moonlogs", prefix) & filters.me)
@@ -69,9 +67,7 @@ async def mupl(client: Client, message: Message):
await message.edit("<b>Uploading Now...</b>") await message.edit("<b>Uploading Now...</b>")
await client.send_document(message.chat.id, link) await client.send_document(message.chat.id, link)
await message.delete() await message.delete()
return await message.edit( return await message.edit("<b>Error: </b><code>LOGS</code> file doesn't exist.")
"<b>Error: </b><code>LOGS</code> file doesn't exist."
)
except Exception as e: except Exception as e:
await message.edit(format_exc(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", "upl [filepath]/[reply to path]*": "Upload a file from your local machine to Telegram",
"dlf": "Download a file from Telegram to your local machine", "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", "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",
} }

View File

@@ -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))) pm_limit = int(os.getenv("PM_LIMIT", env.int("PM_LIMIT", 4)))
test_server = bool(os.getenv("TEST_SERVER", env.bool("TEST_SERVER", False))) 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")
)

View File

@@ -908,10 +908,7 @@ class PromoteHandler:
user_id, user_id,
privileges=ChatPrivileges(**self.common_privileges_promote), privileges=ChatPrivileges(**self.common_privileges_promote),
) )
if ( if len(self.cause.split()) > 1 and self.message.chat.type == "group":
len(self.cause.split()) > 1
and self.message.chat.type == "group"
):
await self.client.set_administrator_title( await self.client.set_administrator_title(
self.chat_id, self.chat_id,
user_id, user_id,

View File

@@ -5,11 +5,11 @@ from lexica import AsyncClient, Client
def ImageModels(): def ImageModels():
models = Client().models['models']['image'] models = Client().models["models"]["image"]
dict_models = {} dict_models = {}
for model in models: for model in models:
model_id = model['id'] model_id = model["id"]
model_name = model['name'] model_name = model["name"]
dict_models[model_name] = model_id dict_models[model_name] = model_id
return dict_models return dict_models
@@ -17,18 +17,18 @@ def ImageModels():
async def ImageGeneration(model, prompt): async def ImageGeneration(model, prompt):
try: try:
output = await AsyncClient().generate(model, prompt, "") output = await AsyncClient().generate(model, prompt, "")
if output['code'] != 1: if output["code"] != 1:
return 2 return 2
if output['code'] == 69: if output["code"] == 69:
return output['code'] return output["code"]
task_id, request_id = output['task_id'], output['request_id'] task_id, request_id = output["task_id"], output["request_id"]
await asyncio.sleep(20) await asyncio.sleep(20)
tries = 0 tries = 0
image_url = None image_url = None
resp = await AsyncClient().getImages(task_id, request_id) resp = await AsyncClient().getImages(task_id, request_id)
while True: while True:
if resp['code'] == 2: if resp["code"] == 2:
image_url = resp['img_urls'] image_url = resp["img_urls"]
break break
if tries > 15: if tries > 15:
break break