added link protection, actually need to test it though lol
This commit is contained in:
parent
13cce85cb7
commit
6d5a21e0ad
5 changed files with 50 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,3 @@
|
|||
node_modules/
|
||||
package-lock.json
|
||||
source_output.txt
|
||||
*.txt
|
||||
|
|
|
@ -48,6 +48,7 @@ cd ..
|
|||
echo
|
||||
echo "install: installing tmi node module for the twitch bot"
|
||||
cd twitch-bot
|
||||
touch mods.txt trusted_users.txt
|
||||
npm install tmi.js
|
||||
cd ..
|
||||
|
||||
|
|
|
@ -46,13 +46,19 @@ const opts = {
|
|||
channels: settings.channels
|
||||
};
|
||||
|
||||
const linkProtection = settings.link_protection;
|
||||
const bannedUrlEndings = settings.banned_endings;
|
||||
var modString = "";
|
||||
var mods;
|
||||
|
||||
try {
|
||||
modString = fs.readFileSync('mods.txt', 'utf8');
|
||||
trustedString = fs.readFileSync('trusted_users.txt', 'utf8');
|
||||
modString = modString.replace(/(\r\n|\n|\r)/gm, "");
|
||||
trustedString = trustedString.replace(/(\r\n|\n|\r)/gm, "");
|
||||
console.log('* Loaded mods and trusted users from file.');
|
||||
mods = modString.split(",");
|
||||
trustedUsers = trustedString.split(",");
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
@ -65,10 +71,23 @@ function onMessageHandler (target, context, msg, self) {
|
|||
msg = msg.toLowerCase();
|
||||
var message = msg.trim();
|
||||
|
||||
// link protection stuff, only enables when true in settings.json
|
||||
var findUrlEndings = false;
|
||||
if (linkProtection) {
|
||||
for (var i=urlEndings.length; i--;) {
|
||||
if (message.includes(urlEndings[i])) findUrlEndings = true;
|
||||
else if (message.includes(urlEndings[i].replace('.', '*'))) findUrlEndings = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (message.charAt(0) === settings.command_char) {
|
||||
message = message.substr(1);
|
||||
valid = commands(target, message, user, mods);
|
||||
} else {
|
||||
if (linkProtection && findUrlEndings)
|
||||
if (!linkProtect())
|
||||
reactions(target, message, user);
|
||||
else
|
||||
reactions(target, message, user);
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +159,30 @@ function reactions (target, message, user) {
|
|||
});
|
||||
}
|
||||
|
||||
function linkProtect() {
|
||||
if (trustedUsers.indexOf(user) === -1) {
|
||||
if (message.search("http") !== -1 || message.search("www.") !== -1 || findUrlEndings) {
|
||||
urlAttempt = message;
|
||||
urlAttemptUser = user;
|
||||
console.log(`! ${user} tried to post a URL. Warned and timedout for 10 seconds. Message: "${urlAttempt}"`);
|
||||
client.say(target, `/timeout ${user} 10 Links from untrusted users are deleted as a protection against chat bots.`);
|
||||
client.say(target, `@${user} Your link was deleted because you haven't been in my chat before. If you have a legitimate link and aren't a bot, let me know!`);
|
||||
// is a bot, don't go farther
|
||||
return true;
|
||||
} else {
|
||||
trustedString = trustedString + `,${user}`;
|
||||
trustedString = trustedString.replace(/(\r\n|\n|\r)/gm, "");
|
||||
trustedUsers.push(user);
|
||||
fs.writeFile('/home/bryson/git/bryzinga-bot/trusted-users', `${trustedString}`, function (err) {
|
||||
if (err) return console.log(err);
|
||||
console.log(`* ${user} is now a trusted chatter.`);
|
||||
});
|
||||
// not a bot, move on to reactions
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Twitch bot initialization
|
||||
const client = new tmi.client(opts);
|
||||
|
||||
|
|
|
@ -3,5 +3,8 @@
|
|||
"bot_token": "enter the token that you generate here",
|
||||
"your_username": "YOUR_username_not_your_bots_username",
|
||||
"channels" : [ "enter the channel names for the bot to join", "you can have multiple!" ],
|
||||
"command_char": "!"
|
||||
"command_char": "!",
|
||||
|
||||
"link_protection": false,
|
||||
"banned_endings": [".com", ".org", ".edu", ".gov", ".gg", ".io", ".tv", ".uk", ".net", ".ca", ".de", ".jp", ".fr", ".au", ".us", ".ru", ".ch", ".it", ".nl", ".se", ".no", ".es", ".mil", ".xyz", ".top", ".info"]
|
||||
}
|
||||
|
|
Reference in a new issue