Поправлена проверка на упоминание бота.
This commit is contained in:
parent
7fc6373fca
commit
44d6b3528b
2 changed files with 22 additions and 10 deletions
|
|
@ -54,10 +54,14 @@ async def any_message_handler(message: Message):
|
||||||
if bot_user is None:
|
if bot_user is None:
|
||||||
bot_user = await message.bot.get_me()
|
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)
|
if message.reply_to_message and message.reply_to_message.from_user.id == bot_user.id:
|
||||||
elif message.reply_to_message and message.reply_to_message.from_user.id == bot_user.id:
|
|
||||||
message_text = message.text
|
message_text = message.text
|
||||||
|
else:
|
||||||
|
# Сообщение содержит @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:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import re
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from vkbottle.bot import Message
|
from vkbottle.bot import Message
|
||||||
|
|
@ -39,12 +40,19 @@ async def any_message_handler(message: Message):
|
||||||
if bot_user is None:
|
if bot_user is None:
|
||||||
bot_user = (await message.ctx_api.groups.get_by_id()).groups[0]
|
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)
|
if message.reply_message and message.reply_message.from_id == -bot_user.id:
|
||||||
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:
|
|
||||||
message_text = message.text
|
message_text = message.text
|
||||||
|
else:
|
||||||
|
# Сообщение содержит @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:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue