Z
Z
Zakhar Ivanov2019-10-19 23:17:38
In contact with
Zakhar Ivanov, 2019-10-19 23:17:38

How to make a black list of words for a bot in vk (node.js vk-io)?

Hello, I am making a bot in VK for a conversation on node.js (vk-io).
It is necessary to make it read all the messages that are written in the conversation and if there are words from the black list, it will issue a warning.

const {VK, Keyboard, MessageContext } = require('vk-io');
const vk = new VK();
const {updates} = vk; 
const fs = require("fs");

vk.setOptions({
    token: 'токен', // токен группы
    apiMode: 'parallel',
  pollingGroupId: 187748785 // 1 замени на id группы 
}); 

vk.updates.hear(/hello/i, context => (
  context.send('World!')
));

vk.updates.hear(/^(?:Информация|Выговоры)$/i, (message) => {
  return message.send(` Таблица пиздюлей:
  Ренат - 1
  Макс -  1`);
});

const catsPurring = [
  'http://liferussian.ru/vk/test.mp3'
];

vk.updates.hear('Помощь', async (context) => {
  await context.send(`
    Мои команнды :
    /naxuy - послать говноеда
    Информация | Выговоры - тут все янсо
    А дальше хз что, ок?
  `);
});

vk.updates.hear('/naxuy', async (context) => {
  const link = catsPurring[Math.floor(Math.random() * catsPurring.length)];

  await Promise.all([
    context.send('Подожди, не много,сучка'),

    context.sendAudioMessage(link)
  ]);
});

client.on('message' async message => ){

let blacklisted = ['lettuce', 'geyporno', 'привет']

let foundInText = false;
for (var i in blacklisted){
  if (message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
}

if (foundInText){
  context.send('Подожди, не много,сучка');
}

vk.updates.start().catch(console.error);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timofey Gelazonia, 2019-10-26
@xZeldon

Very timely, of course, but nevertheless) If we take the code from the comments above as a basis and correct it a little, it will turn out something like this:

vk.updates.on('message', (context, next ) => {

  let blacklisted = ['lettuce', 'geyporno', 'привет']
  
  let foundInText = false;
  for (var i in blacklisted){
    if (context.text.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
  }
  
  if (foundInText){
    context.send('Подожди, не много,сучка');
  } else {
    next()
  }
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question