Поправлена проверка на упоминание бота.
This commit is contained in:
parent
7fc6373fca
commit
44d6b3528b
2 changed files with 22 additions and 10 deletions
|
|
@ -54,12 +54,16 @@ async def any_message_handler(message: Message):
|
|||
if bot_user is None:
|
||||
bot_user = await message.bot.get_me()
|
||||
|
||||
if message.content_type == ContentType.TEXT and message.text.find('@' + bot_user.username) != -1:
|
||||
message_text = message.text.replace('@' + bot_user.username, bot_user.first_name)
|
||||
elif message.reply_to_message and message.reply_to_message.from_user.id == bot_user.id:
|
||||
# Ответ на сообщение бота
|
||||
if message.reply_to_message and message.reply_to_message.from_user.id == bot_user.id:
|
||||
message_text = message.text
|
||||
else:
|
||||
return
|
||||
# Сообщение содержит @bot_username
|
||||
bot_username_mention = '@' + bot_user.username
|
||||
if message.content_type == ContentType.TEXT and message.text.find(bot_username_mention) != -1:
|
||||
message_text = message.text.replace(bot_username_mention, bot_user.first_name)
|
||||
else:
|
||||
return
|
||||
|
||||
if message.from_user.first_name and message.from_user.last_name:
|
||||
user_name = "{} {}".format(message.from_user.first_name, message.from_user.last_name)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import re
|
||||
from typing import Optional
|
||||
|
||||
from vkbottle.bot import Message
|
||||
|
|
@ -39,14 +40,21 @@ async def any_message_handler(message: Message):
|
|||
if bot_user is None:
|
||||
bot_user = (await message.ctx_api.groups.get_by_id()).groups[0]
|
||||
|
||||
if message.text is not None and message.text.find('@' + bot_user.screen_name) != -1:
|
||||
message_text = message.text.replace('@' + bot_user.screen_name, bot_user.name)
|
||||
elif message.text is not None and message.text.find('club' + str(bot_user.id)) != -1:
|
||||
message_text = message.text.replace('club' + str(bot_user.id), bot_user.name)
|
||||
elif message.reply_message and message.reply_message.from_id == -bot_user.id:
|
||||
# Ответ на сообщение бота
|
||||
if message.reply_message and message.reply_message.from_id == -bot_user.id:
|
||||
message_text = message.text
|
||||
else:
|
||||
return
|
||||
# Сообщение содержит @bot_username
|
||||
bot_username_mention = '@' + bot_user.screen_name
|
||||
if message.text is not None and message.text.find(bot_username_mention) != -1:
|
||||
message_text = message.text.replace(bot_username_mention, bot_user.name)
|
||||
else:
|
||||
# Сообщение содержит [club<bot_id>|<some_name>]
|
||||
pattern = r"\[club" + str(bot_user.id) + r"\|(.+)]"
|
||||
if message.text is not None and re.search(pattern, message.text) is not None:
|
||||
message_text = re.sub(pattern, r'\1', message.text)
|
||||
else:
|
||||
return
|
||||
|
||||
user = await message.ctx_api.users.get(user_ids=[message.from_id])
|
||||
if len(user) == 1:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue