Добавлена команда !личность.
This commit is contained in:
parent
651f755b2d
commit
bca3f640ae
6 changed files with 57 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ from aiogram.utils.formatting import Bold
|
||||||
import utils
|
import utils
|
||||||
from messages import *
|
from messages import *
|
||||||
import tg.tg_database as database
|
import tg.tg_database as database
|
||||||
|
from .default import reset_ai_chat_context
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
|
|
||||||
|
|
@ -72,6 +73,27 @@ async def set_greeting_handler(message: Message, bot: Bot):
|
||||||
await message.answer('Приветствие изменено.')
|
await message.answer('Приветствие изменено.')
|
||||||
|
|
||||||
|
|
||||||
|
@router.message(F.text == "!личность")
|
||||||
|
async def set_ai_prompt_handler(message: Message, bot: Bot):
|
||||||
|
chat_id = message.chat.id
|
||||||
|
chat = database.DB.create_chat_if_not_exists(chat_id)
|
||||||
|
if chat['active'] == 0:
|
||||||
|
await message.answer(MESSAGE_CHAT_NOT_ACTIVE)
|
||||||
|
return
|
||||||
|
|
||||||
|
if not await tg_user_is_admin(chat_id, message.from_user.id, bot):
|
||||||
|
await message.answer(MESSAGE_PERMISSION_DENIED)
|
||||||
|
return
|
||||||
|
|
||||||
|
if message.reply_to_message is None:
|
||||||
|
await message.answer(MESSAGE_NEED_REPLY)
|
||||||
|
return
|
||||||
|
|
||||||
|
database.DB.chat_update(chat_id, ai_prompt=message.reply_to_message.text)
|
||||||
|
reset_ai_chat_context(chat_id)
|
||||||
|
await message.answer('Личность ИИ изменена.')
|
||||||
|
|
||||||
|
|
||||||
@router.message(F.text == "!предупреждение")
|
@router.message(F.text == "!предупреждение")
|
||||||
async def warning_handler(message: Message, bot: Bot):
|
async def warning_handler(message: Message, bot: Bot):
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,11 @@ def get_ai_chat_context(chat_id: int) -> ChatContext:
|
||||||
return chat_contexts[chat_id]
|
return chat_contexts[chat_id]
|
||||||
|
|
||||||
|
|
||||||
|
def reset_ai_chat_context(chat_id: int):
|
||||||
|
chat_contexts.pop(chat_id, None)
|
||||||
|
get_ai_chat_context(chat_id)
|
||||||
|
|
||||||
|
|
||||||
async def ai_message_handler(message: Message):
|
async def ai_message_handler(message: Message):
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ async def help_handler(message: Message):
|
||||||
response += '!старт - начать работу в чате\n'
|
response += '!старт - начать работу в чате\n'
|
||||||
response += '!правила* - изменить правила\n'
|
response += '!правила* - изменить правила\n'
|
||||||
response += '!приветствие* - изменить приветствие новичков\n'
|
response += '!приветствие* - изменить приветствие новичков\n'
|
||||||
|
response += '!личность* - изменить описание личности ИИ\n'
|
||||||
response += '!предупреждение* - выдать предупреждение участнику\n'
|
response += '!предупреждение* - выдать предупреждение участнику\n'
|
||||||
response += '\n'
|
response += '\n'
|
||||||
response += Italic('Команды с пометкой * нужно вызывать в ответном сообщении.')
|
response += Italic('Команды с пометкой * нужно вызывать в ответном сообщении.')
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from vkbottle_types.codegen.objects import MessagesGetConversationMembers
|
||||||
from messages import *
|
from messages import *
|
||||||
import utils
|
import utils
|
||||||
import vk.vk_database as database
|
import vk.vk_database as database
|
||||||
|
from .default import reset_ai_chat_context
|
||||||
|
|
||||||
labeler = BotLabeler()
|
labeler = BotLabeler()
|
||||||
|
|
||||||
|
|
@ -126,6 +127,28 @@ async def set_birthday_handler(message: Message):
|
||||||
await message.answer('Уведомление о дне рождения изменено.')
|
await message.answer('Уведомление о дне рождения изменено.')
|
||||||
|
|
||||||
|
|
||||||
|
@labeler.chat_message(text="!личность")
|
||||||
|
async def set_ai_prompt_handler(message: Message):
|
||||||
|
chat_id = message.peer_id
|
||||||
|
chat = database.DB.create_chat_if_not_exists(chat_id)
|
||||||
|
if chat['active'] == 0:
|
||||||
|
await message.answer(MESSAGE_CHAT_NOT_ACTIVE)
|
||||||
|
return
|
||||||
|
|
||||||
|
chat_members = await message.ctx_api.messages.get_conversation_members(peer_id=chat_id, extended=False)
|
||||||
|
if not vk_user_is_admin(message.from_id, chat_members):
|
||||||
|
await message.answer(MESSAGE_PERMISSION_DENIED)
|
||||||
|
return
|
||||||
|
|
||||||
|
if message.reply_message is None:
|
||||||
|
await message.answer(MESSAGE_NEED_REPLY)
|
||||||
|
return
|
||||||
|
|
||||||
|
database.DB.chat_update(chat_id, ai_prompt=message.reply_message.text)
|
||||||
|
reset_ai_chat_context(chat_id)
|
||||||
|
await message.answer('Личность ИИ изменена.')
|
||||||
|
|
||||||
|
|
||||||
@labeler.chat_message(text="!предупреждение")
|
@labeler.chat_message(text="!предупреждение")
|
||||||
async def warning_handler(message: Message):
|
async def warning_handler(message: Message):
|
||||||
chat_id = message.peer_id
|
chat_id = message.peer_id
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,11 @@ def get_ai_chat_context(chat_id: int) -> ChatContext:
|
||||||
return chat_contexts[chat_id]
|
return chat_contexts[chat_id]
|
||||||
|
|
||||||
|
|
||||||
|
def reset_ai_chat_context(chat_id: int):
|
||||||
|
chat_contexts.pop(chat_id, None)
|
||||||
|
get_ai_chat_context(chat_id)
|
||||||
|
|
||||||
|
|
||||||
async def ai_message_handler(message: Message):
|
async def ai_message_handler(message: Message):
|
||||||
chat_id = message.peer_id
|
chat_id = message.peer_id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ async def rules_handler(message: Message):
|
||||||
response += '!приветствие* - изменить приветствие новичков\n'
|
response += '!приветствие* - изменить приветствие новичков\n'
|
||||||
response += '!возвращение* - изменить приветствие при возвращении\n'
|
response += '!возвращение* - изменить приветствие при возвращении\n'
|
||||||
response += '!деньрождения* - изменить уведомление о дне рождения\n'
|
response += '!деньрождения* - изменить уведомление о дне рождения\n'
|
||||||
|
response += '!личность* - изменить описание личности ИИ\n'
|
||||||
response += '!предупреждение* - выдать предупреждение участнику\n'
|
response += '!предупреждение* - выдать предупреждение участнику\n'
|
||||||
response += '!исключить* - навсегда исключить участника\n'
|
response += '!исключить* - навсегда исключить участника\n'
|
||||||
response += '\n'
|
response += '\n'
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue