mirror of
https://github.com/civsocit/olgram.git
synced 2023-07-22 01:29:12 +03:00
#11 additional user info
This commit is contained in:
parent
90997f5adb
commit
1779a5607d
@ -74,3 +74,8 @@ async def select_chat(bot: Bot, call: types.CallbackQuery, chat: str):
|
|||||||
async def threads(bot: Bot, call: types.CallbackQuery):
|
async def threads(bot: Bot, call: types.CallbackQuery):
|
||||||
bot.enable_threads = not bot.enable_threads
|
bot.enable_threads = not bot.enable_threads
|
||||||
await bot.save(update_fields=["enable_threads"])
|
await bot.save(update_fields=["enable_threads"])
|
||||||
|
|
||||||
|
|
||||||
|
async def additional_info(bot: Bot, call: types.CallbackQuery):
|
||||||
|
bot.enable_additional_info = not bot.enable_additional_info
|
||||||
|
await bot.save(update_fields=["enable_additional_info"])
|
||||||
|
@ -156,6 +156,11 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
|||||||
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="threads",
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="threads",
|
||||||
chat=empty))
|
chat=empty))
|
||||||
)
|
)
|
||||||
|
keyboard.insert(
|
||||||
|
types.InlineKeyboardButton(text="Дополнительная информация",
|
||||||
|
callback_data=menu_callback.new(level=3, bot_id=bot.id, operation="additional_info",
|
||||||
|
chat=empty))
|
||||||
|
)
|
||||||
keyboard.insert(
|
keyboard.insert(
|
||||||
types.InlineKeyboardButton(text="<< Назад",
|
types.InlineKeyboardButton(text="<< Назад",
|
||||||
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,
|
callback_data=menu_callback.new(level=1, bot_id=bot.id, operation=empty,
|
||||||
@ -163,8 +168,10 @@ async def send_bot_settings_menu(bot: Bot, call: types.CallbackQuery):
|
|||||||
)
|
)
|
||||||
|
|
||||||
thread_turn = "включены" if bot.enable_threads else "выключены"
|
thread_turn = "включены" if bot.enable_threads else "выключены"
|
||||||
|
info_turn = "включена" if bot.enable_additional_info else "выключена"
|
||||||
text = dedent(f"""
|
text = dedent(f"""
|
||||||
<a href="https://olgram.readthedocs.io/ru/latest/threads.html">Потоки сообщений</a>: <b>{thread_turn}</b>
|
<a href="https://olgram.readthedocs.io/ru/latest/threads.html">Потоки сообщений</a>: <b>{thread_turn}</b>\n
|
||||||
|
<a href="https://olgram.readthedocs.io/ru/latest/user_info.html">Дополнительная информация</a>: <b>{info_turn}</b>\n
|
||||||
""")
|
""")
|
||||||
await edit_or_create(call, text, reply_markup=keyboard, parse_mode="HTML")
|
await edit_or_create(call, text, reply_markup=keyboard, parse_mode="HTML")
|
||||||
|
|
||||||
@ -402,6 +409,9 @@ async def callback(call: types.CallbackQuery, callback_data: dict, state: FSMCon
|
|||||||
if operation == "threads":
|
if operation == "threads":
|
||||||
await bot_actions.threads(bot, call)
|
await bot_actions.threads(bot, call)
|
||||||
return await send_bot_settings_menu(bot, call)
|
return await send_bot_settings_menu(bot, call)
|
||||||
|
if operation == "additional_info":
|
||||||
|
await bot_actions.additional_info(bot, call)
|
||||||
|
return await send_bot_settings_menu(bot, call)
|
||||||
if operation == "reset_text":
|
if operation == "reset_text":
|
||||||
await bot_actions.reset_bot_text(bot, call)
|
await bot_actions.reset_bot_text(bot, call)
|
||||||
return await send_bot_text_menu(bot, call)
|
return await send_bot_text_menu(bot, call)
|
||||||
|
4
olgram/migrations/models/11_20220317080443_update.sql
Normal file
4
olgram/migrations/models/11_20220317080443_update.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
-- upgrade --
|
||||||
|
ALTER TABLE "bot" ADD "enable_additional_info" BOOL NOT NULL DEFAULT False;
|
||||||
|
-- downgrade --
|
||||||
|
ALTER TABLE "bot" DROP COLUMN "enable_additional_info";
|
@ -42,6 +42,7 @@ class Bot(Model):
|
|||||||
outgoing_messages_count = fields.BigIntField(default=0)
|
outgoing_messages_count = fields.BigIntField(default=0)
|
||||||
|
|
||||||
enable_threads = fields.BooleanField(default=False)
|
enable_threads = fields.BooleanField(default=False)
|
||||||
|
enable_additional_info = fields.BooleanField(default=False)
|
||||||
|
|
||||||
def decrypted_token(self):
|
def decrypted_token(self):
|
||||||
cryptor = DatabaseSettings.cryptor()
|
cryptor = DatabaseSettings.cryptor()
|
||||||
|
@ -56,6 +56,8 @@ async def message_handler(message: types.Message, *args, **kwargs):
|
|||||||
return SendMessage(chat_id=message.chat.id,
|
return SendMessage(chat_id=message.chat.id,
|
||||||
text="Вы заблокированы в этом боте")
|
text="Вы заблокированы в этом боте")
|
||||||
|
|
||||||
|
in_thread = False
|
||||||
|
|
||||||
# Пересылаем сообщение в супер-чат
|
# Пересылаем сообщение в супер-чат
|
||||||
if is_super_group and bot.enable_threads:
|
if is_super_group and bot.enable_threads:
|
||||||
thread_first_message = await _redis.get(_thread_uniqie_id(bot.pk, message.chat.id))
|
thread_first_message = await _redis.get(_thread_uniqie_id(bot.pk, message.chat.id))
|
||||||
@ -63,6 +65,7 @@ async def message_handler(message: types.Message, *args, **kwargs):
|
|||||||
# переслать в супер-чат, отвечая на предыдущее сообщение
|
# переслать в супер-чат, отвечая на предыдущее сообщение
|
||||||
try:
|
try:
|
||||||
new_message = await message.copy_to(super_chat_id, reply_to_message_id=int(thread_first_message))
|
new_message = await message.copy_to(super_chat_id, reply_to_message_id=int(thread_first_message))
|
||||||
|
in_thread = True
|
||||||
except exceptions.BadRequest:
|
except exceptions.BadRequest:
|
||||||
new_message = await message.forward(super_chat_id)
|
new_message = await message.forward(super_chat_id)
|
||||||
await _redis.set(_thread_uniqie_id(bot.pk, message.chat.id), new_message.message_id,
|
await _redis.set(_thread_uniqie_id(bot.pk, message.chat.id), new_message.message_id,
|
||||||
@ -78,6 +81,15 @@ async def message_handler(message: types.Message, *args, **kwargs):
|
|||||||
await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id,
|
await _redis.set(_message_unique_id(bot.pk, new_message.message_id), message.chat.id,
|
||||||
pexpire=ServerSettings.redis_timeout_ms())
|
pexpire=ServerSettings.redis_timeout_ms())
|
||||||
|
|
||||||
|
if bot.enable_additional_info and not in_thread:
|
||||||
|
user_info = "От пользователя: "
|
||||||
|
if message.from_user.full_name:
|
||||||
|
user_info += message.from_user.full_name
|
||||||
|
if message.from_user.username:
|
||||||
|
user_info += " | @" + message.from_user.username
|
||||||
|
user_info += f" | #{message.from_user.id}"
|
||||||
|
await message.bot.send_message(super_chat_id, text=user_info, reply_to_message_id=new_message.message_id)
|
||||||
|
|
||||||
bot.incoming_messages_count = F("incoming_messages_count") + 1
|
bot.incoming_messages_count = F("incoming_messages_count") + 1
|
||||||
await bot.save(update_fields=["incoming_messages_count"])
|
await bot.save(update_fields=["incoming_messages_count"])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user