Skip to content

Commit

Permalink
Custom commands!
Browse files Browse the repository at this point in the history
You can now add custom commands. Also added all the current commands to
the commands table. Useful for next commit, because that will be the
command page 👍
  • Loading branch information
Mstiekema committed Jan 29, 2017
1 parent b7ebdf9 commit ee19f8b
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 64 deletions.
96 changes: 64 additions & 32 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ connection.query(
connection.query(
'CREATE TABLE commands (' +
'id INT AUTO_INCREMENT PRIMARY KEY,' +
'commandName VARCHAR(50),' +
'response VARCHAR(500))',
'level INT,' +
'globalCd INT,' +
'userCd INT)',
'commName VARCHAR(50),' +
'response VARCHAR(500),' +
'commDesc VARCHAR(500),' +
'commUse VARCHAR(500),' +
'level INT DEFAULT 100,' +
'cdType VARCHAR(50),' +
'cd INT)',
function (err, result) {if (err) {return}}
)

Expand Down Expand Up @@ -92,33 +94,63 @@ connection.query(
function (err, result) {if (err) {return}}
)

connection.query('insert into user set ? ', {"name": options.identity.admin, "points": 0, "num_lines": 0, "level": 500, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
if (options.identity.admin != options.channels[0]) {
connection.query('insert into user set ? ', {"name": options.channels[0], "points": 0, "num_lines": 0, "level": 400, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
connection.query('insert into user set ? ', {"name": options.identity.username, "points": 0, "num_lines": 0, "level": 300, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
} else {
connection.query('insert into user set ? ', {"name": options.identity.username, "points": 0, "num_lines": 0, "level": 300, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
}
// connection.query('insert into user set ? ', {"name": options.identity.admin, "points": 0, "num_lines": 0, "level": 500, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
// if (options.identity.admin != options.channels[0]) {
// connection.query('insert into user set ? ', {"name": options.channels[0], "points": 0, "num_lines": 0, "level": 400, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
// connection.query('insert into user set ? ', {"name": options.identity.username, "points": 0, "num_lines": 0, "level": 300, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
// } else {
// connection.query('insert into user set ? ', {"name": options.identity.username, "points": 0, "num_lines": 0, "level": 300, "isMod": true }, function (err, result) {if (err) {console.log(err)}})
// }

var sql = "insert into module (moduleName, moduleDescription, state) values ?";
var moduleSettings = [
["dungeonActive", "Dungeon", false],
['useTwitchAPI', "All the commands that use the Twitch API to fetch data", true],
['basicCommands', "Some of the bais commands to use", true],
['updateProfile', "Creates a profile for each user with points, lines, etc.", true],
['fetchProfile', "Fetches information from all users, such as points and lines", true],
['owCommands', "Used to fetch the rank of any OW player", true],
['roulette', "Point gambling mini-game", true],
['slot', "Point gambling mini-game", true],
['dungeon', "Point gambling mini-game with the entire chat", true],
['fourtwenty', "Timer that notifies chat it's 16:20", true],
['twitter', "Pushes the users Twitter each 20 minutes", true],
['getSongs', "Songrequest from chat (player still buggy)", true],
['mod', "Module that enables purge, timeout and ban words to be enabled", true],
['link', "Gives non-subs a 20 second timeout if they post a link in chat", true],
['sub', "Notifies chat if a user subs or resubs", true],
['timeout', "Saves a log if a user is timed out or banned", true],
];
connection.query(sql, [moduleSettings], function (err, result) {if (err) {console.log(err)}})
// var sql = "insert into module (moduleName, moduleDescription, state) values ?";
// var moduleSettings = [
// ["dungeonActive", "Dungeon", false],
// ['useTwitchAPI', "All the commands that use the Twitch API to fetch data", true],
// ['basicCommands', "Some of the bais commands to use", true],
// ['updateProfile', "Creates a profile for each user with points, lines, etc.", true],
// ['fetchProfile', "Fetches information from all users, such as points and lines", true],
// ['owCommands', "Used to fetch the rank of any OW player", true],
// ['roulette', "Point gambling mini-game", true],
// ['slot', "Point gambling mini-game", true],
// ['dungeon', "Point gambling mini-game with the entire chat", true],
// ['fourtwenty', "Timer that notifies chat it's 16:20", true],
// ['twitter', "Pushes the users Twitter each 20 minutes", true],
// ['getSongs', "Songrequest from chat (player still buggy)", true],
// ['mod', "Module that enables purge, timeout and ban words to be enabled", true],
// ['link', "Gives non-subs a 20 second timeout if they post a link in chat", true],
// ['sub', "Notifies chat if a user subs or resubs", true],
// ['timeout', "Saves a log if a user is timed out or banned", true],
// ];
// connection.query(sql, [moduleSettings], function (err, result) {if (err) {console.log(err)}})

var sql2 = "insert into commands (commName, response, commDesc, cdType, cd, level, commUse) values ?"
var standardCommands = [
["!test", "This is a command xD", null, "user", 10, 100, null],
["!repo", "You can find the GitHub repo for the bot over at https://github.com/Mstiekema/Yucibot", null, "user", 10, 100, null],
["!google", null, "Makes a google search for you", "global", 10, 100, "!google Where can I download more ram?"],
["!lmgtfy", null, "Makes a let me Google that for you search", "global", 10, 100, "!lmgtfy Where can I find the nearest KFC?"],
["!viewers", null, "Returns the current viewcount if the stream is live", "global", 10, 100, null],
["!game", null, "Returns the current game if the stream is live", "global", 10, 100, null],
["!title", null, "Returns the current title if the stream is live", "global", 10, 100, null],
["!owrank", null, "Returns the streamer's or the user's OW rank", "global", 10, 100, "!owrank Mstiekema#2237"],
["!roulette", null, "Fun point minigame where you can gamble with your points", "user", 300, 100, "!roulette 12345"],
["!slot", null, "Fun point minigame where you can gamble with your points", "user", 300, 100, null],
["!enter", null, "Joins the dungeon queue, if one is active", "user", 1, 100, null],
["!rq", null, "Returns a random recorded quote from the current user", "user", 30, 100, null],
["!points", null, "Bot whispers your amount of points", "global", 5, 100, null],
["!lines", null, "Returns the amount of lines the user has typed", "global", 20, 100, null],
["!totallines", null, "Returns the total recorded lines in chat", "global", 30, 100, null],
["!currentsong", null, "Returns the song that's currently playing", "global", 1, 100, null],
["!songrequest", null, "Allows subs to request songs in chat", "global", 10, 150, "!songrequest Enjoy the silence - Depeche Mode \n !songrequest https://www.youtube.com/watch?v=aGSKrC7dGcY \n !songrequest aGSKrC7dGcY"],
["!resetpoints", null, "Resets the points of the target", "global", 10, 300, "!resetpoints Mstiekema"],
["!addpoints", null, "Adds points to the target", "user", 1,300, "!addpoints kimodaptyl 12345"],
["!addcommand", null, "Adds a command to the bot", "user", 1, 300, "!addcommand !test This is a testing command :)"],
["!removecommand", null, "Removes a command from the bot", "global", 10, 300, "!remove command !test"],
["!addpurge", null, "Adds a purge word to the banlist", "user", 1, 300, "!addpurge fuck"],
["!addtimeout", null, "Adds a timeout word to the banlist", "user", 1, 300, "!addtimeout fuck"],
["!addban", null, "Adds a ban word to the banlist", "user", 1, 300, "!addtimeout fuck"],
["1quit", null, "Makes the bot quit", "user", 1, 300, null]
]
connection.query(sql2, [standardCommands], function (err, result) {if (err) console.log(err)})

connection.end();
35 changes: 14 additions & 21 deletions modules/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,30 @@ var connect = require('../app.js')
var bot = connect.bot
var request = require("request");
var cd = require("./cooldown.js")
var connection = require("./connection.js")
var clientID = options.identity.clientId

module.exports = {
customCommands: function(channel, user, message, self) {
connection.query('select * from commands WHERE commDesc IS NULL', function(err, result) {
var comm = message.split(" ")[0]
var commands = result.map(function(a) {return a.commName;})
var check = new RegExp(commands.join("|")).test(comm)
if (check != false) {
var commInfo = result[commands.indexOf(comm)]
cd.command(channel, user, message, comm, commInfo.cdType, parseInt(commInfo.cd), commInfo.response)
}
})
},
basicCommands: function (channel, user, message, self) {
if (message.startsWith("!test")) {
function test() {
bot.say(channel, "This is a command xD")
console.log('Did the thing')
}
cd.cooldown("test", "global", user.username, 10, test)
}
else if (message.startsWith("!twitter")) {
function twitter() {bot.say(channel, channel.substring(1) + "'s Twitter is https://www.twitter.com/" + options.identity.twitter)}
cd.cooldown("twitter", "global", user.username, 10, twitter)
}
else if (message.startsWith("!repo") || message.startsWith("!github")) {
function repo() {bot.say(channel,"You can find the GitHub repo for the bot over at https://github.com/Mstiekema/Yucibot")}
cd.cooldown("repo", "global", user.username, 10, repo)
}
else if (message.startsWith("!slap")) {
function slap() {bot.say(channel, user.username + " slapped" + message.substring(message.indexOf(" ")) + " in the face")}
cd.cooldown("slap", "global", user.username, 10, slap)
}
else if (message.startsWith("!google")) {
if (message.startsWith("!google")) {
function google() {
var q = message.substring(message.indexOf(" ") + 1);
var question = q.split(' ').join('+');
var base = "https://www.google.nl/search?q=";
var link = base + question
bot.say(channel, user.username + " Google is je beste vriend! " + link)}
cd.cooldown("google", "global", user.username, 10, google)
cd.cooldown("google", "global", usewr.username, 10, google)
}
else if (message.startsWith("!lmgtfy")) {
function lmgtfy() {
Expand Down
56 changes: 47 additions & 9 deletions modules/cooldown.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var tmi = require('tmi.js');
var options = require('../config.js')
var connect = require('../app.js')
var bot = connect.bot
var request = require("request");
var clientID = options.identity.clientId
var cooldowns = [];
var tmi = require('tmi.js');
var options = require('../config.js')
var connect = require('../app.js')
var bot = connect.bot
var request = require("request");
var clientID = options.identity.clientId
var cooldowns = [];

module.exports = {
cooldown: function(command, type, user, cooldown, exc) {
cooldown: function(command, cdtype, user, cooldown, exc) {
var toCD = user + command
var cd = cooldown * 1000
if(type == "user") {
if(cdtype == "user") {
if (cooldowns.indexOf(command) != -1) {
return
} else {
Expand Down Expand Up @@ -42,5 +42,43 @@ module.exports = {
exc()
}
}
},
command: function(channel, user, message, command, cdtype, cooldown, botSay) {
if (message.startsWith(command)) {
var toCD = user.username + command
var cd = cooldown * 1000
if(cdtype == "user") {
if (cooldowns.indexOf(command) != -1) {
return
} else {
if (cooldowns.indexOf(toCD) != -1) {
return
} else {
cooldowns.push(toCD)
cooldowns.push(command)
setTimeout(function() {
var index = cooldowns.indexOf(toCD);
cooldowns.splice(index, 1);
}, cd);
setTimeout(function() {
var index = cooldowns.indexOf(command);
cooldowns.splice(index, 1);
}, 10000);
bot.say(channel, botSay)
}
}
} else {
if (cooldowns.indexOf(command) != -1) {
return
} else {
cooldowns.push(command)
setTimeout(function() {
var index = cooldowns.indexOf(command);
cooldowns.splice(index, 1);
}, cd);
bot.say(channel, botSay)
}
}
}
}
}
3 changes: 1 addition & 2 deletions modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ module.exports = {
}, function () {}, true );
},
twitter: function () {
console.log("test")
var channel = JSON.stringify(options.channels).slice(2, -2);
new CronJob('* */20 * * *', function() {
new CronJob('*/20 * * * *', function() {
bot.say(channel, "Follow me on Twitter: https://twitter.com/" + options.identity.twitter)
}, function () {}, true );
}
Expand Down
28 changes: 28 additions & 0 deletions modules/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,33 @@ module.exports = {
if(link != null) { if (user.mod == false) { if (user.username != channel.substring(1)) { if (user.subscriber != true) {
bot.timeout(channel, user.username, 20, "Non-subs are not allowed to post links")
}}}}
},
commandManagement: function(channel, user, message, self) {
if (user.mod || user.username == channel.substring(1)) {
if(message.startsWith("!addcommand")) {
var info = message.split(" ")
var commName = info[1]
info.splice(0, 2)
var commInfo = {
commName: commName,
response: info.join(" "),
cdType: "global",
cd: 10,
}
connection.query('insert into commands set ?', commInfo, function (err, result) {if (err) {return}})
bot.whisper(user.username, "Succesfully added the new command " + commName)
}
if(message.startsWith("!removecommand")) {
var info = message.split(" ")
var commName = info[1]
connection.query('delete from commands where commName = ?', commName, function (err, result) {
if (err) {
bot.whisper(user.username, "Couldn't find the command you were looking for")
} else {
bot.whisper(user.username, "Succesfully removed the following command: " + commName)
}
})
}
}
}
}
2 changes: 2 additions & 0 deletions modules/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var exp = module.exports = {}

exp.commands = function(channel, user, message, self) {
streaminfo.fetchInfo()
basic.customCommands(channel, user, message, self)
mod.commandManagement(channel, user, message, self)
connection.query('select * from module', function(err, result) {
if (result[1].state == 1) {
basic.useTwitchAPI(channel, user, message, self)
Expand Down

0 comments on commit ee19f8b

Please sign in to comment.