Answer the question
In order to leave comments, you need to log in
Is it possible to improve and / or make something more correct (Bot VK)?
Can something be done better/better here? I would be grateful for your help (I'm new)
const { VK } = require('vk-io');
const vk = new VK({ token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" });
const acc = require('./acc.json');
const fs = require('fs');
function unixDate(stamp) {
let date = new Date(stamp),
year = date.getFullYear(),
month = (("0" + (date.getMonth() + 1)).slice(-2)),
day = (("0" + (date.getDate())).slice(-2))
return `${day}.${month}.${year}`;
};
function unixTime(stamp) {
let date = new Date(stamp),
hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
mins = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
return `${hour}:${mins}`;
};
function getDate() {
return unixDate(Date.now());
};
function getTime() {
return unixTime(Date.now());
};
vk.updates.use((ctx, next) => {
if (Number(ctx.senderId) <= 0 || ctx.senderId === undefined) return;
if (!acc.users.find(x => x.vk === ctx.senderId)) {
acc.number++;
acc.users.push({
id: acc.number,
vk: ctx.senderId,
nickname: 'Неизвестно',
level: 1,
admin: 0,
balance: 0,
winGame: 0,
lossGame: 0,
dateReg: getDate(),
timeReg: getTime(),
});
};
if (ctx.senderId < 0) return;
return next();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question