if event.object.text == "кик":
vk.method("messages.removeChatUser", {
"chat_id": event.object.peer_id - 2000000000,
"member_id": event.obj.reply_message['from_id']})
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
print(domen)
return vk.method("users.get", {"user_ids": domen})[0]["id"]
text = event.obj["text"].split(' ')
if (len(text) == 2) and text[0] == "кик":
vk.method("messages.removeChatUser", {"chat_id": event.chat_id, "member_id": get_user(text[1])})
def get_name(uid: int) -> str:
data = vk.method("users.get", {"user_ids": uid})[0]
return "{} {}".format(data["first_name"], data["last_name"])
f"Приветствую [id{event.user_id}|{get_name(event.user_id)}]"
data.json
и заполните его так{
"conversations": [
]
}
import vk_api
import json
vk_session = vk_api.VkApi(token='ТОКЕН')
vk = vk_session.get_api()
index = 1
while True:
try:
chat_info = vk.messages.getChat(chat_id=index)
data = json.load(open('data.json', encoding='utf-8'))
srt_info = {'title': f'{chat_info["title"]}', 'id': f'{chat_info["id"]}'}
data['conversations'].append(srt_info)
with open('data.json', 'w', encoding='utf-8') as file:
json.dump(data, file, indent=2, ensure_ascii=False)
file.close()
index += 1
except Exception as e:
print(repr(e))
if event.object.text == "Кик" or event.object.text == "кик":
vk.method("messages.removeChatUser", {
"chat_id": event.object.peer_id - 2000000000,
"member_id": event.obj.reply_message['from_id']})
longpoll = VkBotLongPoll(vk_session, idgrup)
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.users.get(user_ids=domen)[0]["id"]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
text = event.obj["message"]["text"].split()
if (len(text) == 2) and text[0] == "кик":
try:
vk.messages.removeChatUser(
chat_id=event.chat_id,
member_id=get_user(text[1])
)
except Exception as e:
vk.messages.send(
chat_id=event.chat_id,
message="Произошла ошибка.",
random_id=0
)
vk.messages.markAsUnreadConversation(peer_id=пир айди)
def get_members(peer_id: int) -> list:
return vk.method("messages.getConversationMembers", {
"peer_id": peer_id
})["items"]
def get_admins(peer_id: int) -> list:
return [
i["member_id"] for i in get_members(peer_id)
if i.get("is_admin", False)
]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.text == "какая-то команда":
if event.obj.from_id in get_admins(event.obj.peer_id):
#выполнение команды
def get_name(uid: int) -> str:
data = vk.method("users.get", {"user_ids": uid})[0]
return "{} {}".format(data["first_name"], data["last_name"])
full_name = get_name(тут юзер айди)
messages.getChat
недоступен.messages.getConversationsById
def get_chat_title(chat):
return vk.method("messages.getConversationsById", {"peer_ids": chat})['items'][0]['chat_settings']['title']
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
print('Название беседы: ' + get_chat_title(event.obj.peer_id))
except Exception as e:
print(repr(e))
vk.method("groups.enableOnline", {"group_id": тут айди группы})