Ignore message if it contains a URL
This commit is contained in:
parent
3eb67166f7
commit
66fed01b1b
41
bot.js
41
bot.js
|
|
@ -171,30 +171,45 @@ function onMessageHandler (channel, userstate, message, self) {
|
||||||
console.log(`* buttsbot: User not authorized`);
|
console.log(`* buttsbot: User not authorized`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// ignore commands
|
||||||
if (message.startsWith("!"))
|
if (message.startsWith("!"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// ignore ignored users
|
||||||
if (config.ignoredUsers.includes(userstate['display-name']) || config.ignoredUsers.includes(userstate['username'])) {
|
if (config.ignoredUsers.includes(userstate['display-name']) || config.ignoredUsers.includes(userstate['username'])) {
|
||||||
console.log(`* User ${userstate['username']} is on the ignore list.`);
|
console.log(`* User ${userstate['username']} is on the ignore list.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ignore messages containing URLs
|
||||||
|
let regex = /((http(s)?(\:\/\/))*(www\.)?([\w\-\.\/])*(\.[a-zA-Z]{2,3}\/?))[^\s\b\n|]*[^.,;:\?\!\@\^\$ -]/g;
|
||||||
|
let matches = message.match(regex);
|
||||||
|
if (matches && matches.length > 0) {
|
||||||
|
console.log(`* Message contained URL - skip`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// split messages into word array and try to determine syllabes
|
||||||
|
var words = message.split(' ');
|
||||||
|
var syllables = words.map(syllabify);
|
||||||
|
|
||||||
|
// calculate syllabe count
|
||||||
|
var syllableCount = 0;
|
||||||
|
syllables.forEach((s) => {
|
||||||
|
syllableCount += s.length;
|
||||||
|
});
|
||||||
|
|
||||||
|
// ignore message if it doesn't contain enough syllabes
|
||||||
|
if (syllableCount < config.syllableCount) {
|
||||||
|
console.log(`* Message had too few syllables`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// random chance
|
||||||
|
// TODO: find a better alternative
|
||||||
var number = Math.random() * 100;
|
var number = Math.random() * 100;
|
||||||
if (number <= config.chance) {
|
if (number <= config.chance) {
|
||||||
|
|
||||||
var words = message.split(' ');
|
|
||||||
var syllables = words.map(syllabify);
|
|
||||||
var syllableCount = 0;
|
|
||||||
|
|
||||||
syllables.forEach((s) => {
|
|
||||||
syllableCount += s.length;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (syllableCount < config.syllableCount) {
|
|
||||||
console.log(`* Message had too few syllables`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var buttCount = Math.ceil(words.length / config.limit);
|
var buttCount = Math.ceil(words.length / config.limit);
|
||||||
|
|
||||||
var randomNumbersUsed = [];
|
var randomNumbersUsed = [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user