aboutsummaryrefslogtreecommitdiff
path: root/twitch-bot
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2022-03-12 23:44:04 -0700
committerBryson Steck <steck.bryson@gmail.com>2022-03-12 23:44:04 -0700
commit6d5a21e0add8ec42f0bdd59dd9508af5a035a598 (patch)
tree24240b7b9a918edf25aad62d0752e42eb9c4db0d /twitch-bot
parent13cce85cb7e473b44ab3cdb53f4906e77ab2ad75 (diff)
downloadlset-6d5a21e0add8ec42f0bdd59dd9508af5a035a598.tar
lset-6d5a21e0add8ec42f0bdd59dd9508af5a035a598.tar.gz
lset-6d5a21e0add8ec42f0bdd59dd9508af5a035a598.tar.bz2
added link protection, actually need to test it though lol
Diffstat (limited to 'twitch-bot')
-rw-r--r--twitch-bot/bot.js45
-rw-r--r--twitch-bot/mods.txt0
-rw-r--r--twitch-bot/settings.json5
3 files changed, 48 insertions, 2 deletions
diff --git a/twitch-bot/bot.js b/twitch-bot/bot.js
index ec54b48..f4a2140 100644
--- a/twitch-bot/bot.js
+++ b/twitch-bot/bot.js
@@ -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)
}
@@ -64,12 +70,25 @@ function onMessageHandler (target, context, msg, self) {
const user = context.username;
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 {
- reactions(target, message, user);
+ 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);
diff --git a/twitch-bot/mods.txt b/twitch-bot/mods.txt
deleted file mode 100644
index e69de29..0000000
--- a/twitch-bot/mods.txt
+++ /dev/null
diff --git a/twitch-bot/settings.json b/twitch-bot/settings.json
index a665436..e785f78 100644
--- a/twitch-bot/settings.json
+++ b/twitch-bot/settings.json
@@ -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"]
}