Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Модули
const { VK } = require('vk-io');
const vk = new VK();
const fs = require('fs');
const colors = require('colors');
const config = require("./config.js");
// database
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync('database/db.json');
const db = low(adapter);
db.defaults({ users: [] }).write();
//
db.getUser = async(ID) => {
let user = db.get('users').find({ id: ID }).value();
if (!user) {
db.get('users').push({
const { VK, Keyboard } = require('vk-io');
const { Wizard } = require('./middlewares/wizard');
const { getSessionMiddleware } = require('./middlewares/session');
const scenes = require('./scenes');
const vk = new VK({
token: process.env.TOKEN
});
const wizard = new Wizard();
// Register scenes
for (const scene of scenes) {
wizard.addScene(scene);
}
// Skip outbox messages
vk.updates.on('message', async (context, next) => {
if (context.isOutbox) {
return;
}
const { VK } = require('vk-io');
const fetch = require('node-fetch');
const fs = require('fs');
const vk = new VK({
token: process.env.TOKEN
});
/**
* Sets custom uploadUrl or timeout
*/
vk.upload.photoAlbum({
source: {
uploadUrl: '',
timeout: 60e3,
values: [
// Examples of parameters below
]
}
});
const { VK, Keyboard } = require('vk-io');
const vk = new VK({
token: process.env.TOKEN
});
vk.updates.on('message', (context, next) => {
const { messagePayload } = context;
context.state.command = messagePayload && messagePayload.command
? messagePayload.command
: null;
return next();
});
// Simple wrapper for commands
const hearCommand = (name, conditions, handle) => {
if (typeof handle !== 'function') {
const { VK } = require('vk-io');
const vk = new VK({
token: process.env.TOKEN
});
vk.updates.hear(/hello/i, context => (
context.send('World!')
));
vk.updates.start().catch(console.error);
const { VK } = require('vk-io');
const { SessionManager } = require('@vk-io/session');
const vk = new VK({
token: process.env.TOKEN
});
const sessionManager = new SessionManager();
vk.updates.on('message', sessionManager.middleware);
vk.updates.hear('/counter', async (context) => {
const { session } = context;
if (session.counter === undefined) {
session.counter = 0;
}
session.counter += 1;
const { VK } = require('vk-io');
const vk = new VK({
token: process.env.TOKEN
});
vk.updates.hear('/start', async (context) => {
await context.send(`
My commands list
/cat - Cat photo
/purr - Cat purring
/time - The current date
/reverse - Reverse text
`);
});
vk.updates.hear('/cat', async (context) => {
await Promise.all([
async configure() {
if (this.isConfigured) {
return this.logger.warn('Бот уже сконфигурирован');
}
if (!this.token) {
throw new ConfigureError('Не указан токен бота');
}
this.vk = new VK({
apiLimit: this.apiLimit,
apiMode: this.apiMode,
token: this.token
});
await this.vk.updates.start();
if (!this.groupId) {
this.groupId = this.vk.options.pollingGroupId;
}
if (this.groupId < 0) {
this.groupId = -this.groupId;
}
if (this.vk.options.pollingGroupId !== this.groupId) {
const { VK } = require('vk-io');
const { SessionManager } = require('@vk-io/session');
const { SceneManager, StepScene } = require('@vk-io/scenes');
const vk = new VK({
token: process.env.TOKEN
});
const sessionManager = new SessionManager();
const sceneManager = new SceneManager();
sceneManager.addScene(new StepScene('signup', [
(context) => {
if (context.scene.step.firstTime || !context.text) {
return context.send('What\'s your name?');
}
context.scene.state.firstName = context.text;
return context.scene.step.next();
},