C
C
cenox2021-02-08 23:14:30
Python
cenox, 2021-02-08 23:14:30

How to make a kick at the mention of VK?

Liba - vkbottle
There is already a kick on the response to the message, I want to do it by mention and link
Script of the kick to reply to the message:

@bot.on.chat_message(lower=True, text=['кик', 'бан', 'ban', 'kick'])
@swear(VKError, exception_handler=exc_kick)
async def kick(message: Message):
  members = await message.api.messages.get_conversation_members(
        peer_id=message.peer_id
    )
  admins = [member.member_id for member in members.items if member.is_admin]
  if message.from_id not in admins:
    await message('ты не одмен беседы.')
  else:
    txt = message.reply_message.text
    await bot.api.messages.remove_chat_user(message.peer_id - 2000000000, message.reply_message.from_id)
    return "Пользователь успешно исключён"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WolfInChains, 2021-02-09
@cen0x

The mention comes in this form [id12345|Вася Пупкин]
. You just need to remove everything unnecessary and pass the id to the user exclusion method

def get_user_id(pattern: str) -> int:
    if "[id" in pattern:
        return int(pattern.split("|")[0].replace("[id", ""))

According to the link something like this, it’s not difficult to rewrite for your lib
def get_user_id(pattern: str) -> int:
    if "vk.com/" in pattern:
        domen = pattern.split("/")[-1]
        return vk.method("users.get", {"user_ids": domen})[0]["id"]

Can this be combined into one function?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question