Witam, mam problem pewien problem z chat botem do twitcha. Chciałbym, aby odpisywał "Witaj :) . Wylosowałem: LOSOWA_LICZBA" po każdej wiadomości, która w treści będzie miała chociaż jeden element z tablicy dKeywords i chociaż jeden element z tablicy dKeywords1. Próbowałem z array.some();, ale nie wychodzi mi. Jestem, jak widać, zielony i nie ogarniam zbytnio jsa. Męczyłem się z tym ponad 8 godzin, więc pomyślałem, że poproszę o pomoc.
const tmi = require('tmi.js');
const opts = {
identity: {
username: "**********",
password: "**********"
},
channels: ["**********", "**********", "**********", "**********", "**********"]
};
const client = new tmi.client(opts);
client.on('message', onMessageHandler);
client.on('connected', onConnectedHandler);
client.connect();
function onMessageHandler (target, context, msg, self)
{
if (self) { return; } // Ignore messages from the bot
const aha = msg.toLowerCase();
const commandName = aha.trim();
const dKeywords1 = ['cześć', 'siema'];
const dKeywords = ['123', '456'];
if (commandName.indexOf(dKeywords1) !== -1 && commandName.indexOf(dKeywords) !== -1)
{
const num = rollDice();
client.say(target, `Witaj :) . Wylosowałem: ${num}`);
console.log(`* Wykonano`);
}
else
{
console.log(`* ${commandName}`);
}
}
function rollDice () {
const sides = 100;
return Math.floor(Math.random() * sides) + 1;
}
function onConnectedHandler (addr, port) {
console.log(`* Connected to ${addr}:${port}`);
}