some fix with emoji function
This commit is contained in:
@@ -40,6 +40,17 @@ TEST = bdf.settings['Settings']['test']
|
||||
BotDB = bdf.get_db()
|
||||
|
||||
|
||||
@private_router.message(
|
||||
ChatTypeFilter(chat_type=["private"]),
|
||||
Command("emoji")
|
||||
)
|
||||
async def handle_emoji_message(message: types.Message, state: FSMContext):
|
||||
user_emoji = check_user_emoji(message)
|
||||
await state.set_state("START")
|
||||
if user_emoji is not None:
|
||||
await message.answer(f'Твоя эмодзя - {user_emoji}', parse_mode='HTML')
|
||||
|
||||
|
||||
@private_router.message(
|
||||
ChatTypeFilter(chat_type=["private"]),
|
||||
Command("restart")
|
||||
@@ -50,7 +61,7 @@ async def handle_restart_message(message: types.Message, state: FSMContext):
|
||||
await message.forward(chat_id=GROUP_FOR_LOGS)
|
||||
await state.set_state("START")
|
||||
await update_user_info('love', message)
|
||||
check_user_emoji(message.from_user.id)
|
||||
check_user_emoji(message)
|
||||
await message.answer('Я перезапущен!', reply_markup=markup, parse_mode='HTML')
|
||||
except Exception as e:
|
||||
logger.error(f"Произошла ошибка handle_restart_message. Ошибка:{str(e)}")
|
||||
@@ -70,7 +81,7 @@ async def handle_start_message(message: types.Message, state: FSMContext):
|
||||
try:
|
||||
await message.forward(chat_id=GROUP_FOR_LOGS)
|
||||
await update_user_info('love', message)
|
||||
check_user_emoji(message.from_user.id)
|
||||
check_user_emoji(message)
|
||||
await state.set_state("START")
|
||||
logger.info(
|
||||
f"Формирование приветственного сообщения для пользователя. Сообщение: {message.text} "
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -424,19 +424,21 @@ async def update_user_info(source: str, message: types.Message):
|
||||
BotDB.update_date_for_user(date, user_id)
|
||||
|
||||
|
||||
def check_user_emoji(user_id: int):
|
||||
if BotDB.check_emoji_for_user(user_id=user_id) is None:
|
||||
def check_user_emoji(message: types.Message):
|
||||
user_id = message.from_user.id
|
||||
user_emoji = BotDB.check_emoji_for_user(user_id=user_id)
|
||||
if user_emoji is None:
|
||||
user_emoji = get_random_emoji()
|
||||
BotDB.update_emoji_for_user(user_id=user_id, emoji=user_emoji)
|
||||
return user_emoji
|
||||
|
||||
|
||||
def get_random_emoji():
|
||||
attempts = 0
|
||||
while attempts < 100:
|
||||
print(attempts)
|
||||
user_emoji = random.choice(emoji_list)
|
||||
if not BotDB.check_emoji(user_emoji):
|
||||
return user_emoji
|
||||
attempts += 1
|
||||
logger.error("Не удалось найти уникальный эмодзи после нескольких попыток.")
|
||||
return None
|
||||
return "Эмоджи не определен"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
def get_message(username: str, type_message: str):
|
||||
constants = {
|
||||
'HELLO_MESSAGE': "Привет, username!👋🏼&Меня зовут Виби, я бот канала 'Влюбленный Бийск'❤🤖"
|
||||
@@ -25,7 +23,7 @@ def get_message(username: str, type_message: str):
|
||||
"&Мы рассмотрим и ответим тебе в ближайшее время☺️❤️",
|
||||
"DEL_MESSAGE": "username, напиши свое обращение или предложение✍"
|
||||
"&Мы рассмотрим и ответим тебе в ближайшее время☺❤",
|
||||
"BYE_MESSAGE": "Если позднее захочешь предложить еще один пост или обратиться к админам с вопросом, то просто пришли в чат команду 👉 /start"
|
||||
"BYE_MESSAGE": "Если позднее захочешь предложить еще один пост или обратиться к админам с вопросом, то просто пришли в чат команду 👉 /restart"
|
||||
"&&И тебе пока!👋🏼❤️",
|
||||
"USER_ERROR": "Увы, я не понимаю тебя😐💔 Выбери один из пунктов в нижнем меню, а затем пиши.",
|
||||
"QUESTION": "Сообщение успешно отправлено❤️ Ответим, как только сможем😉",
|
||||
|
||||
Reference in New Issue
Block a user