while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
message = event.obj['message']
global text = message['text']
if text.lower() == "привет":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": text,
"random_id": 0})
elif event.object.peer_id == event.object.from_id:
if text.lower() == "привет":
vk.method("messages.send", {"user_id": event.object.from_id, "message": text,
"random_id": 0})
const { VK, uploadErrors, Keyboard, Context } = require('vk-io');
const vk = new VK();
const commands = [];
const users = require('./users.json');
const chats = require('./chats.json');
const fs = require('fs');
const { NONAME } = require('dns');
setInterval(async () => {
await saveUsers();
}, 1000);
async function saveUsers()
{
require('fs').writeFileSync('./users.json', JSON.stringify(users, null, '\t'));
require('fs').writeFileSync('./chats.json', JSON.stringify(chats, null, '\t'));
return true;
}
vk.setOptions({ token: '', pollingGroupId: });
/* const { updates, snippets } = vk; */
vk.updates.on('message', async (message, context) => {
if(Number(message.senderId) <= 0) return;
if(/\[club209536507\|(.*)\]/i.test(message.text)) message.text = message.text.replace(/\[clubсудаайдигруппы\|(.*)\]/ig, '').trim();
if(!chats.find(x=>x.id===message.chatId))
{
const chat = await vk.api.messages.getConversationsById({ peer_ids: message.peerId, extended: 1, fields: 'chat_settings', group_id: 209536507 }); // это обязательно
const [peer] = chat.items;
const chat_info = peer.chat_settings;
message.send(`Ваша беседа успешно активирована.`)
chats.push({
id: message.chatId,
cid: chats.length,
name: `${chat_info.title}`,
owner: chat_info.owner_id,
greeting: null,
members: []
})
}
const peer = chats.filter(x => x.id === message.chatId)[0];
const user = peer.members.filter(x => x.id === message.senderId)[0];
if(!peer.members.find(x=>x.id===message.senderId))
{
const [user_info] = await vk.api.users.get({ user_id: message.senderId });
peer.members.push({
id: message.senderId,
nick:
ban: false,
points: 0,
warn: 0,
mute: 0,
role: 0
})
}
if(peer.owner==message.senderId) return user.role=4
if(!users.find(x=>x.id===message.senderId))
{
const [user_info] = await vk.api.users.get({ user_id: message.senderId });
users.push({
id: message.senderId,
gban: false,
tag: `${user_info.first_name}`
})
}
message.user = users.find(x=> x.id === message.senderId);
const bot = (text, params) => {
return message.send(` ${message.user.mention ? `@id${message.user.id} (${message.user.nick})` : `${message.user.nick}`}, ${text}`, params);
}
const command = commands.find(x=> x[0].test(message.text));
if(!command) return;
message.args = message.text.match(command[0]);
await command[1](message, bot);
let date = new Date;
message.user.last_sms = date;
message.user.message_sms += 1;
return context();
});
vk.updates.on(['chat_kick_user'], (next, context) => {
const peer = chats.filter(x => x.id === next.chatId)[0];
const user = peer.members.filter(x => x.id === next.eventMemberId)[0];
vk.api.messages.removeChatUser({ chat_id: next.chatId, user_id: user.id });
return context();
});