vk.updates.on('message', async (next, context) => {
let name = await vk.api.users.get({
user_ids: next.senderId
});
users.push({
id: next.senderId,
firstname: name[0].first_name,
lastname: name[0].last_name,
warns: 0,
role: 1,
flip: 0,
botmute: 0,
rank: "Участник",
ban: false,
isBanned: "Нет",
tempban: 0,
mute: 0,
mutesleft: 0,
violations: 0,
nick: "Не установлен"
})
fs.writeFileSync("./users.json", JSON.stringify(users, null, "\t"))
return context()
})
function findNick(arr, nick) {
const res = arr.find(i => i.nick == nick);
if (res) return;
return arr;
}
console.log(findNick(users, 'хай'));
const json = `[{${users}]`;
const data = JSON.parse(json);
function findNick(arr, nick) {
const res = arr.find(i => i.nick == nick);
if (res) return;
return arr;
}
console.log(findNick(data, 'хай'));
const { VK } = require('vk-io');
const users = require('./users.json');
const fs = require('fs');
const vk = new VK({
token: '...'
});
setInterval(async () => {
fs.writeFileSync("./users.json", JSON.stringify(users, null, "\t"))
}, 500);
vk.updates.on('message', async (next, context) => {
let name = await vk.api.users.get({
user_ids: next.senderId
});
users.push({
id: next.senderId,
firstname: name[0].first_name,
lastname: name[0].last_name,
warns: 0,
role: 1,
flip: 0,
botmute: 0,
rank: "Участник",
ban: false,
isBanned: "Нет",
tempban: 0,
mute: 0,
mutesleft: 0,
violations: 0,
nick: "Не установлен"
})
return context()
})