aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2022-03-11 16:23:51 -0700
committerBryson Steck <steck.bryson@gmail.com>2022-03-11 16:23:51 -0700
commit9eb5b3102216ea60169acff71c15e13db0264e44 (patch)
tree4c2a7afa2b146bc96e2c6da0fdc1cf9a756556a4
parentb3e1bd3a1dfdf45fb3d735b3ba9912c66c37e3b9 (diff)
downloadlset-9eb5b3102216ea60169acff71c15e13db0264e44.tar
lset-9eb5b3102216ea60169acff71c15e13db0264e44.tar.gz
lset-9eb5b3102216ea60169acff71c15e13db0264e44.tar.bz2
finished cleaning twitch bot
-rw-r--r--twitch-bot/bot.js263
-rw-r--r--twitch-bot/commands.json10
-rw-r--r--twitch-bot/mod_commands.json0
-rw-r--r--twitch-bot/mods.txt0
-rw-r--r--twitch-bot/reacts.json10
-rw-r--r--twitch-bot/settings.json6
6 files changed, 131 insertions, 158 deletions
diff --git a/twitch-bot/bot.js b/twitch-bot/bot.js
index a782acc..b81830c 100644
--- a/twitch-bot/bot.js
+++ b/twitch-bot/bot.js
@@ -1,99 +1,96 @@
const tmi = require('tmi.js');
const timed = require('./timedMessages.js');
+const fs = require('fs');
+
+// read settings and reactions json files
+fs.readFile('./settings.json', 'utf8', (err, data) => {
+ if (err) {
+ console.log(`Error reading settings file from disk: ${err}`);
+ process.exit(1);
+ } else {
+ // parse JSON string to JSON object
+ const settings = JSON.parse(data);
+ }
+}
+
+fs.readFile('./reacts.json', 'utf8', (err, data) => {
+ if (err) {
+ console.log(`Error reading reacts file from disk: ${err}`);
+ process.exit(1);
+ } else {
+ // parse JSON string to JSON object
+ const reacts = JSON.parse(data);
+ }
+}
+
+fs.readFile('./commands.json', 'utf8', (err, data) => {
+ if (err) {
+ console.log(`Error reading commands file from disk: ${err}`);
+ process.exit(1);
+ } else {
+ // parse JSON string to JSON object
+ const commands = JSON.parse(data);
+ }
+}
+
+fs.readFile('./mod_commands.json', 'utf8', (err, data) => {
+ if (err) {
+ console.log(`Error reading mod commands file from disk: ${err}`);
+ process.exit(1);
+ } else {
+ // parse JSON string to JSON object
+ const mod_commands = JSON.parse(data);
+ }
+}
const opts = {
identity: {
- username: '',
- password: ''
+ username: settings.bot_username,
+ password: settings.bot_token
},
- channels: [
- ''
- ]
+ channels: settings.channels
};
-const client = new tmi.client(opts);
-
-// Register our event handlers (defined below)
-client.on('message', onMessageHandler);
-client.on('connected', onConnectedHandler);
-
-// Connect to Twitch:
-client.connect();
-
-const fs = require('fs')
var modString = "";
var mods;
-var trustedString = "";
-var trustedUsers;
try {
modString = fs.readFileSync('', 'utf8');
- trustedString = fs.readFileSync('', 'utf8');
- console.log('');
modString = modString.replace(/(\r\n|\n|\r)/gm, "");
- trustedString = trustedString.replace(/(\r\n|\n|\r)/gm, "");
mods = modString.split(",");
- trustedUsers = trustedString.split(",");
} catch (err) {
console.error(err)
}
-var urlAttempt = "";
-var urlAttemptUser = "";
-const urlEndings = ['.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'];
var modCommand = false;
+// Twitch bot initialization
+const client = new tmi.client(opts);
+
+// Register our event handlers (defined below)
+client.on('message', onMessageHandler);
+client.on('connected', onConnectedHandler);
+
+// Connect to Twitch:
+client.connect();
+
+// Notify when connected
+function onConnectedHandler (addr, port) {
+ console.log(`* Main Bot successfully connected to ${addr}:${port}`);
+}
+
function onMessageHandler (target, context, msg, self) {
if (self) { return; } // Ignore messages from the bot
- //console.log(msg);
- //console.log(target);
- //console.log(context);
- var user = context.username;
+ const user = context.username;
msg = msg.toLowerCase();
var message = msg.trim();
- var findUrlEndings = false;
- 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) === '!') {
+ if (message.charAt(0) === settings.command_char) {
message = message.substr(1);
- valid = commands(target, message, user, mods)
- }
- // Link protection
- 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, let me know!`);
- } else {
- trustedString = trustedString + `,${user}`;
- trustedString = trustedString.replace(/(\r\n|\n|\r)/gm, "");
- trustedUsers.push(user);
- fs.writeFile('', `${trustedString}`, function (err) {
- if (err) return console.log(err);
- console.log(`* ${user} is now a trusted chatter.`);
- });
- }
-}
-
- // easter eggs
- if (message.search("") !== -1) {
- client.say(target, `You talkin' to me punk? WideHardo`);
- }
- if (message.search("you") !== -1 && message.search("good") !== -1) {
- client.say(target, `Thanks ~uwu~ AYAYA`);
- }
- if (message.search("bruh") !== -1) {
- client.say(target, `${user} is 12 years old and shouldn't be on Twitch.`);
+ valid = commands(target, message, user, mods);
+ } else {
+ reactions(target, message, user);
}
- if (message.search ("hi ") !== -1 && message.length <= 12) {
- client.say(target, `I'm new here.`);
- }
}
function commands (target, commandName, user, mods) {
@@ -101,53 +98,38 @@ function commands (target, commandName, user, mods) {
var valid = false;
var isMod = false;
if (mods.indexOf(user) >= 0) isMod = true;
-
- if (commandName === 'commands') {
- valid = true;
- client.say(target, `@${user} Here is the list of commands: !about !bttv !commands !discord !emotes !followage !hits !join !uptime`);
- } else if (commandName === 'about') {
- valid = true;
- client.say(target, `@${user} `);
-// } else if (commandName === 'pb') {
-// valid = true;
-// client.say(target, 'Mario Kart Wii PBs PogChamp \\\\ Nitro Tracks: 33:30:196 (IGT, 49th) \\\\ Retro Tracks: 31m 41s 540ms (IGT, 18th)');
- } else if (commandName === 'bttv') {
- valid = true;
- client.say(target, `@${user} If you can't see this emote on desktop (or Android I guess) -> WideHardo then install the BetterTTV browser extension here! -> https://betterttv.com/`);
- } else if (commandName === 'emotes') {
- valid = true;
- client.say(target, `@${user} (!bttv) Channel Emotes: EZ Clap pepeD HACKERMANS pepeJAM NODDERS Drake catJAM BOOBA funkyPls PauseChamp WAYTOODANK gachiGASM Cope TRUEING 4Weird 5Head AYAYA FeelsOkayMan FeelsWeirdMan HandsUp KEKW KKonaW LULW monkaW OMEGALUL Pepega PepegaPhone PepeLaugh PepoG PepoThink Pog POGGERS PogO PogU Sadge WideHardo widepeepoHappy widepeepoSad YEP`);
- } else if (commandName === 'followage') {
- valid = true;
- printHTML(`@${user} You have been following for`, `followage//${user}`, '');
- } else if (commandName === 'uptime') {
- valid = true;
- printHTML(`@${user} has been live for`, `uptime/`, '');
- } else if (commandName === 'join') {
- valid = true;
- client.say(target, `Friend Code: 3356-0850-0440 (To join a race simply add this friend code and join the game when it lets you! Requires CTGP or Wiimmfi-patched MKWii disc. You can only join when the "OPENHOST" message appears on stream lmao)`);
- } else if (commandName === 'discord') {
- valid = true;
- client.say(target, `The OFFICIAL Discord is now live! Come join if you love steak. Or any meat for that matter. Or even if you don't like meat. If you're a vegetarian, we have those weird ass veggie options too. Just join pls lmao: https://discord.gg/c8BjmFPhJt`);
-// } else if (commandName === 'lounge') {
-// valid = true;
-// client.say(target, `Lounge is the biggest competetive gateway for Mario Kart Wii for both Nintendo and CTGP-R tracks. With ranks similar to VALORANT, the goal is to compete for the highest rank possible by earning LR and MMR before the season ends by playing "mogis". To learn more about mogis, type "!mogis".`);
-// } else if (commandName === 'mogis') {
-// valid = true;
-// client.say(target, `Mogis consist of 12 tracks seperated between 3 grands prix. Players vote to play either FFA, 2v2, 3v3, 4v4 or 6v6. The team/player with the highest amount of points overall wins.`);
- } else if (commandName === 'hits') {
- valid = true;
- client.say(target, `NOT IN EFFECT NOW, SMP HAS NOT STARTED -> Donate to start a hit on a player on the server! $3 minimum with the description containing the name of the streamer. To donate, click on the loon in my bio.`);
+
+ if (commandName === "help") {
+ var allCommands = [];
+ var finalString = "";
+ commands.forEach(command => {
+ allCommands.push(command.command);
+ });
+ allCommands.forEach(command => {
+ finalString = finalString + command.command;
+ });
+ client.say(target, `Here is the list of commands: ${finalString}`);
+ } else {
+ commands.forEach(command => {
+ if (message.search(command.command) !== -1) {
+ client.say(target, `${command.reply}`);
+ valid = true;
+ break;
+ }
+ });
}
if (valid === false) {
- valid = modCommands(target, commandName, isMod);
+ if (isMod) {
+ valid = modCommands(target, commandName, isMod);
+ }
}
+
if (valid) {
console.log(`* ${user} executed !${commandName}`);
} else {
if (modCommand === false) {
- client.say(target, `@${user} Unknown command "!${commandName}". Type !commands for all commands. :)`);
+ client.say(target, `@${user} Unknown command "${settings.command_char}${commandName}". Type ${settings.command_char}help for all commands.`);
}
console.warn(`! ${user} tried to execute unknown/banned command !${commandName}`);
}
@@ -155,61 +137,26 @@ function commands (target, commandName, user, mods) {
function modCommands(target, commandName, isMod) {
var valid = false;
- commandName = commandName.split(" ");
- if (commandName[0] === 'allowurl') {
- valid = true;
- modCommand = true;
- if (isMod) {
- if (urlAttempt !== "") client.say(target, `Here was the message posted in chat by ${urlAttemptUser}: "${urlAttempt}"`);
- else client.say(target, `There hasn't been a link that was blocked at the moment.`);
- } else {
- valid = false;
- client.say(target, `Only mods can run this command. PepeLaugh`);
+ mod_commands.forEach(command => {
+ if (message.search(command.command) !== -1) {
+ if (!isMod) {
+ client.say(target, `Only moderators can run this command...`);
+ } else {
+ client.say(target, `${command.reply}`);
+ valid = true;
+ break;
+ }
}
- }
+ });
return valid;
}
-
-function onConnectedHandler (addr, port) {
- console.log(`* Main Bot successfully connected to ${addr}:${port}`);
+function reactions (target, message, user) {
+ reacts.forEach(react => {
+ if (message.search(react.trigger) !== -1) {
+ client.say(target, `${react.reply}`);
+ }
+ });
}
-// Get HTML contents ----------------------------------------------------------------------
-
-const getScript = (url) => {
- return new Promise((resolve, reject) => {
- const http = require('http'),
- https = require('https');
-
- let client = http;
-
- if (url.toString().indexOf("https") === 0) {
- client = https;
- }
-
- client.get(url, (resp) => {
- let data = '';
-
- // A chunk of data has been recieved.
- resp.on('data', (chunk) => {
- data += chunk;
- });
-
- // The whole response has been received. Print out the result.
- resp.on('end', () => {
- return resolve(data);
- });
-
- }).on("error", (err) => {
- return reject(err);
- });
- });
-};
-
-function printHTML(beforeMsg, path, afterMsg) {
- (async (url) => {
- client.say('', `${beforeMsg} ${await getScript(url)} ${afterMsg}`);
- })(`https://api.crunchprank.net/twitch/${path}`);
-}
diff --git a/twitch-bot/commands.json b/twitch-bot/commands.json
new file mode 100644
index 0000000..5efa150
--- /dev/null
+++ b/twitch-bot/commands.json
@@ -0,0 +1,10 @@
+[
+ {
+ "command": "commandhere",
+ "reply": "You ran !commandhere, so I sent this message. You can change the ! to whatever string you wish by editing the settings.json file"
+ },
+ {
+ "command": "cool",
+ "reply": "You ran a cool command!"
+ }
+]
diff --git a/twitch-bot/mod_commands.json b/twitch-bot/mod_commands.json
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/twitch-bot/mod_commands.json
diff --git a/twitch-bot/mods.txt b/twitch-bot/mods.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/twitch-bot/mods.txt
diff --git a/twitch-bot/reacts.json b/twitch-bot/reacts.json
index e69de29..583ca28 100644
--- a/twitch-bot/reacts.json
+++ b/twitch-bot/reacts.json
@@ -0,0 +1,10 @@
+[
+ {
+ "trigger": "If someone says something in this word for word, the bot will reply with the following:",
+ "reply": "Hey! you said that thing that triggered me"
+ },
+ {
+ "trigger": "Just keep adding objects for as many things you want the bot to react to",
+ "reply": "And i will loop over and say the things!"
+ }
+]
diff --git a/twitch-bot/settings.json b/twitch-bot/settings.json
index e69de29..3b076f9 100644
--- a/twitch-bot/settings.json
+++ b/twitch-bot/settings.json
@@ -0,0 +1,6 @@
+{
+ "bot_username": "your_bot_username_here",
+ "bot_token": "enter the token that you generate here",
+ "channels" : [ "enter the channel names for the bot to join", "you can have multiple!" ],
+ "command_char": "!"
+}