aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py221
1 files changed, 205 insertions, 16 deletions
diff --git a/main.py b/main.py
index ad2747f..504b2e0 100644
--- a/main.py
+++ b/main.py
@@ -4,6 +4,7 @@ import base64
import io
import sys
import time
+import string
import gconfig
@@ -28,6 +29,7 @@ from aiogram.types import (
InputTextMessageContent,
InputRichMessageContent,
InputRichMessage,
+ BufferedInputFile,
Message,
)
from callbacks import *
@@ -36,7 +38,7 @@ from colors import *
from helpers import *
from commands import *
from dotenv import load_dotenv
-from random import uniform, shuffle
+from random import uniform, shuffle, choices
try:
from config import *
@@ -82,15 +84,164 @@ async def guest_middleware(handler, event, data):
else:
return await handler(event, data)
+ bot = data.get("bot")
chat_type = message.sender_chat.type if message.sender_chat else ""
user_id = message.sender_chat.id if message.sender_chat else message.from_user.id
+ config = get_user_config(user_id)
+ prompts = SYSTEM_PROMPTS | config["prompts"]
+ p = prompts[config["prompt"]]
+ # внимание внизу самая умная система осторожнеее!!1!1
+ if user_id in alo_command:
+ if message.chat.id == alo_command[user_id]["chat_id"]:
+ if alo_command[user_id]["action"] == "p_name":
+ alo_command[user_id]["action"] = "p_prompt"
+ alo_command[user_id]["name"] = message.text[:16]
+ return await bot.edit_message_text(
+ text=f"установи промпт для `{alo_command[user_id]['name']}`:",
+ chat_id=alo_command[user_id]["chat_id"],
+ message_id=alo_command[user_id]["message_id"],
+ reply_markup=InlineKeyboardMarkup(
+ inline_keyboard=[
+ [
+ InlineKeyboardButton(
+ text=f"❌ отменить", callback_data=f"p_cancel%{user_id}"
+ ),
+ ],
+ ]
+ )
+ )
+ elif alo_command[user_id]["action"] == "p_prompt":
+ alo_command[user_id]["action"] = None
+ alo_command[user_id]["prompt"] = message.text
+
+ while 1:
+ alo_command[user_id]["id"] = ''.join(choices(string.ascii_letters, k=10))
+ if alo_command[user_id]["id"] not in config["prompts"]:
+ break
+
+ config["prompts"] = config["prompts"] | {
+ alo_command[user_id]["id"]: {
+ "name": alo_command[user_id]["name"],
+ "text": alo_command[user_id]["prompt"],
+ "filer": False,
+ "public": False
+ }
+ }
+
+ set_user_config(
+ user_id,
+ config.get("model"),
+ config.get("stream", True),
+ config.get("call"),
+ config.get("prompt"),
+ config.get("notify"),
+ config.get("markdown"),
+ config["prompts"]
+ )
+
+ return await bot.edit_message_text(
+ text=f"промпт `{alo_command[user_id]['name']}` создан!",
+ chat_id=alo_command[user_id]["chat_id"],
+ message_id=alo_command[user_id]["message_id"],
+ reply_markup=InlineKeyboardMarkup(
+ inline_keyboard=[
+ [
+ InlineKeyboardButton(
+ text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['id']}"
+ ),
+ ],
+ ]
+ )
+ )
+ elif alo_command[user_id]["action"] == "p_e_name":
+ alo_command[user_id]["action"] = None
+ alo_command[user_id]["name"] = message.text[:16]
+
+
+ config["prompts"] = config["prompts"] | {
+ alo_command[user_id]["prompt_id"]: {
+ "name": alo_command[user_id]["name"],
+ "text": config["prompts"][alo_command[user_id]["prompt_id"]]["text"],
+ "filer": config["prompts"][alo_command[user_id]["prompt_id"]]["filer"],
+ "public": config["prompts"][alo_command[user_id]["prompt_id"]]["public"],
+ }
+ }
+
+ set_user_config(
+ user_id,
+ config.get("model"),
+ config.get("stream", True),
+ config.get("call"),
+ config.get("prompt"),
+ config.get("notify"),
+ config.get("markdown"),
+ config["prompts"]
+ )
+
+ return await bot.edit_message_text(
+ text=f"имя промпта было изменено на `{alo_command[user_id]['name']}`.",
+ chat_id=alo_command[user_id]["chat_id"],
+ message_id=alo_command[user_id]["message_id"],
+ reply_markup=InlineKeyboardMarkup(
+ inline_keyboard=[
+ [
+ InlineKeyboardButton(
+ text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['prompt_id']}"
+ ),
+ ],
+ ]
+ )
+ )
+ elif alo_command[user_id]["action"] == "p_e_prompt":
+ alo_command[user_id]["action"] = None
+ alo_command[user_id]["prompt"] = message.text
+
+
+ config["prompts"] = config["prompts"] | {
+ alo_command[user_id]["prompt_id"]: {
+ "name": config["prompts"][alo_command[user_id]["prompt_id"]]["name"],
+ "text": alo_command[user_id]["prompt"],
+ "filer": config["prompts"][alo_command[user_id]["prompt_id"]]["filer"],
+ "public": config["prompts"][alo_command[user_id]["prompt_id"]]["public"],
+ }
+ }
+
+ set_user_config(
+ user_id,
+ config.get("model"),
+ config.get("stream", True),
+ config.get("call"),
+ config.get("prompt"),
+ config.get("notify"),
+ config.get("markdown"),
+ config["prompts"]
+ )
+
+ return await bot.edit_message_text(
+ text=f"текст промпта был изменён.",
+ chat_id=alo_command[user_id]["chat_id"],
+ message_id=alo_command[user_id]["message_id"],
+ reply_markup=InlineKeyboardMarkup(
+ inline_keyboard=[
+ [
+ InlineKeyboardButton(
+ text=f"✅ посмотреть", callback_data=f"vp%{user_id}%{alo_command[user_id]['prompt_id']}"
+ ),
+ ],
+ ]
+ )
+ )
+
+ if p["filer"]:
+ if event.guest_message:
+ return await g_answer("сорри, выбранный промпт с ответом как файл не поддерживает гостевой режим.✅🤝", title="ошибка врат")
+
is_channel = (
ChatType.CHANNEL == chat_type
and message.from_user
and message.from_user.id == 777000
)
current_time = time.time()
- config = get_user_config(user_id)
stream = config.get("stream")
user_text = message.text or message.caption or ""
@@ -374,6 +525,19 @@ async def guest_middleware(handler, event, data):
last_command_time[user_id][1] = False
last_command_time[user_id][2] = []
+ if p["filer"]:
+ if msg:
+ await msg.delete()
+ if result == "":
+ result = " "
+ file = BufferedInputFile(
+ file=result.encode("utf-8"),
+ filename=result.replace("\n", "").replace(" ", "_")[:5] + ".txt"
+ )
+ return await message.reply_document(
+ document=file
+ )
+
try:
if ":" in result and ("poll" in result or "quiz" in result):
pw = ["[poll]", "poll", "quiz"]
@@ -414,7 +578,8 @@ async def guest_middleware(handler, event, data):
else:
poll_type = "regular"
-
+ if msg:
+ await msg.delete()
try:
result = await answer_poll(
@@ -449,7 +614,7 @@ async def guest_middleware(handler, event, data):
if config["markdown"] == "new"
else {"text": result}
)
-
+
try:
if event.guest_message:
await g_answer(message, result, user_id=user_id)
@@ -499,6 +664,11 @@ async def guest_middleware(handler, event, data):
async def inline_handler(inline_query: InlineQuery):
user_id = inline_query.from_user.id
ensure_user(user_id)
+
+ config = get_user_config(user_id)
+
+ prompts = SYSTEM_PROMPTS | config["prompts"]
+ p = prompts[config["prompt"]]
button = InlineKeyboardButton(text="ало жди 📞", callback_data="pasholnaxxuy")
@@ -514,17 +684,29 @@ async def inline_handler(inline_query: InlineQuery):
)
]
else:
- result = [
- InlineQueryResultArticle(
- id="1",
- title="генерация думат",
- description=f'думать "{inline_query.query}" ',
- input_message_content=InputTextMessageContent(
- message_text="я думаю врат... как дела✅"
- ),
- reply_markup=InlineKeyboardMarkup(inline_keyboard=[[button]]),
- )
- ]
+ if p["filer"]:
+ result = [
+ InlineQueryResultArticle(
+ id="1",
+ title="🚫🚫🚫",
+ description=f'отправка как файл в инлайне не поддерживается',
+ input_message_content=InputTextMessageContent(
+ message_text="🚫отправка как файл в инлайне не поддерживается"
+ ),
+ )
+ ]
+ else:
+ result = [
+ InlineQueryResultArticle(
+ id="1",
+ title="генерация думат",
+ description=f'думать "{inline_query.query}" ',
+ input_message_content=InputTextMessageContent(
+ message_text="я думаю врат... как дела✅"
+ ),
+ reply_markup=InlineKeyboardMarkup(inline_keyboard=[[button]]),
+ )
+ ]
await inline_query.answer(results=result, cache_time=0)
@@ -534,10 +716,15 @@ async def chosen_inline_result_handler(chosen_result: ChosenInlineResult):
inline_message_id = chosen_result.inline_message_id
user_id = chosen_result.from_user.id
- add_one_to("stats/inline")
+ config = get_user_config(user_id)
+
+ prompts = SYSTEM_PROMPTS | config["prompts"]
+ p = prompts[config["prompt"]]
if chosen_result.query == "clear":
user_contexts[user_id] = []
+ elif p["filer"]:
+ pass
else:
current_time = time.time()
alo, blocked = is_blocked(user_id)
@@ -549,6 +736,8 @@ async def chosen_inline_result_handler(chosen_result: ChosenInlineResult):
inline_message_id=inline_message_id
)
return
+
+ add_one_to("stats/inline")
if not user_id in last_command_time:
last_command_time[user_id] = [current_time, True, [inline_message_id]]