Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Twitch Chat Commands
- /timeout <username> <time in seconds> -Times out the specified user for x number of seconds
- /timeout <username> – times out the selected user for ten minutes
- /timeout <username> 1 – purges the chat of the user. (Actually it times out the user for one second.)
- /ban <username> – Bans the specified username
- /mods – Calls up list of channel moderators
- /slow – Turns slow mode on. I would prefer to be the only one using this command.
- /slowoff – Turns slow mode off.
- /clear – Clears the chat. We try to use this command sparingly and opt for the ‘purge' command.
- **************** IRC Shit ******************
- https://node-irc.readthedocs.org/en/latest/API.html#client
- */
- console.log("BOT STARTING...");
- console.log("LOADING SETTINGS...");
- var s = require("./settings.js");
- var settings = s.settings;
- console.log("LOADED SETTINGS!");
- console.log("LOADING LIBRARIES...");
- var irc = require("irc"),
- fs = require("fs"),
- jf = require("jsonfile"),
- util = require('util');
- console.log("LOADED LIBRARIES!");
- // CREATING BOT
- console.log("CREATING BOT...");
- var _channels = [];
- for(var i = 0; i < settings.channels.length; i++)
- {
- _channels.push(settings.channels[i].Name);
- }
- var bot = new irc.Client(settings.server, settings.botName,
- {
- channels:
- [
- _channels + " " + settings.password
- ],
- debug: false,
- password: settings.password,
- username: settings.botName
- });
- console.log("BOT CREATED!");
- function System(settings)
- {
- this.settings = settings;
- this.contextContainsNoLink = text => {
- // var re = /(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi;
- // var re = /([a-z0-9_-]+\.)+[a-z]{2,4}\/[^ ]*|(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])|(\s|^)((https?:\/\/|www\.)+[a-z0-9_.\/?=&-]+)/gi;
- var re = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|tv|local|internal|xxx))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@\/?]*)?)(\s+|$)/gi;
- if(text.match(re) != null)
- {
- if(text.indexOf('youtube.com') == -1)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- else
- {
- return true;
- }
- }
- this.botIsCalled = text =>
- {
- var calledName = text.split(" ")[0];
- for(var i = 0; i < this.settings.botNicks.length; i++)
- {
- if(this.settings.botNicks[i] == calledName.toLowerCase())
- {
- return true;
- }
- }
- return false;
- }
- this.getChannel = (callback) =>
- {
- for(var i = 0; i < this.settings.channels.length; i++)
- {
- if(callback(this.settings.channels[i]))
- {
- return this.settings.channels[i];
- }
- }
- return null;
- }
- this.isAdmin = user =>
- {
- for(var i = 0; i < this.settings.admins.length; i++)
- {
- if(this.settings.admins[i] == user)
- {
- return true;
- }
- }
- return false;
- }
- }
- var System = new System(settings);
- function Blacklist(data)
- {
- this.data = data;
- this.containsInContext = data => {
- var newData = data.split(" ");
- for(var i = 0; i < newData.length; i++)
- {
- if(this.exists(newData[i].toLowerCase()))
- {
- return true;
- }
- }
- return false;
- }
- this.getData = () => {
- return this.data;
- }
- this.exists = data => {
- for(var i = 0; i < this.data.length; i++)
- {
- if(this.data[i] == data)
- {
- return true;
- }
- }
- return false;
- }
- this.add = word => {
- this.data.push(word);
- jf.writeFileSync("bl/words.json", this.data);
- }
- this.remove = word => {
- var newData = [];
- for(var i = 0; i < this.data.length; i++)
- {
- if(this.data[i] != word)
- {
- newData.push(this.data[i]);
- }
- }
- this.data = newData;
- jf.writeFileSync("bl/words.json", newData);
- }
- }
- var wordBlacklist = new Blacklist(jf.readFileSync("bl/words.json"));
- // Listen for any message, say to him/her in the room
- bot.addListener("message", function (from, channel, text, message)
- {
- if(text[0] == "!")
- {
- var c = System.getChannel(x => x.Name == channel);
- if(c != null)
- {
- var textSplit = text.split(" ");
- var command = textSplit[0];
- var cmd = command.substr(1, command.length-1);
- switch(cmd)
- {
- case "blacklist":
- if(textSplit.length == 4 && System.isAdmin(from.toLowerCase()))
- {
- switch(textSplit[1].toLowerCase())
- {
- case 'word':
- switch(textSplit[2].toLowerCase())
- {
- case 'add':
- var word = textSplit[3].toLowerCase();
- if(!wordBlacklist.exists(word))
- {
- wordBlacklist.add(word);
- bot.say(channel, "Wort \""+word+"\" hinzugefügt!");
- }
- break;
- case 'remove':
- case 'rem':
- var word = textSplit[3].toLowerCase();
- if(wordBlacklist.exists(word))
- {
- wordBlacklist.remove(word);
- bot.say(channel, "Wort \""+word+"\" entfernt!");
- }
- break;
- }
- break;
- }
- }
- break;
- case 'clear':
- if(System.isAdmin(from.toLowerCase()))
- {
- bot.say(channel, "/clear");
- }
- break;
- }
- }
- }
- else if(wordBlacklist.containsInContext(text) && !System.isAdmin(from))
- {
- bot.say(channel, "/timeout "+from+" 1");
- bot.say(channel, settings.texts.blacklist[0].replace("%name%", from));
- }
- else if(!System.contextContainsNoLink(text) && !System.isAdmin(from))
- {
- bot.say(channel, "/timeout "+from+" 1");
- bot.say(channel, settings.texts.blacklist[1].replace("%name%", from));
- }
- else if(System.botIsCalled(text))
- {
- if(System.isAdmin(from))
- {
- var t = text.split(" ");
- var cmd = "";
- for(var i = 1; i < t.length; i++)
- {
- cmd += t[i];
- }
- bot.say(channel, cmd);
- }
- }
- });
- // Listen for joins
- bot.addListener("join", (channel, who) =>
- {
- var c = System.getChannel(x => x.Name == channel);
- if(c != null)
- {
- c.Viewers = c.Viewers + 1;
- }
- });
- bot.addListener("part", (channel, nick, reason, message) =>
- {
- });
- bot.addListener("quit", (nick, reason, channels, message) =>
- {
- });
- // BOT CONNECTING
- console.log("BOT CONNECTING...");
- bot.addListener("connect", () => {
- bot.say(settings.channels[0].Name, settings.texts.system[0]
- .replace("%bot%", settings.botName)
- .replace("%channel%", settings.channels[0].Name)
- );
- console.log("BOT CONNECTED");
- });
- console.log("BOT STARTED!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement