From 4fcfe918aeeaa1d02de2c817bee0afd3920d861e Mon Sep 17 00:00:00 2001 From: Mstiekema Date: Sun, 29 Jan 2017 15:02:22 +0100 Subject: [PATCH] Added a command page This is going to be reworked a whole lot. Will eventually exclude disabled commands / modules and look way more fancy. --- install.js | 66 ++++++++++++++++++------------------ static/css/yucibot.css | 39 +++++++++++++++------ templates/admin/modules.html | 16 ++++----- templates/commands.html | 37 ++++++++++++++++++-- website.js | 30 +++++++++------- 5 files changed, 121 insertions(+), 67 deletions(-) diff --git a/install.js b/install.js index 67aa098..e23a66a 100644 --- a/install.js +++ b/install.js @@ -6,8 +6,8 @@ connection.query( 'id INT AUTO_INCREMENT PRIMARY KEY,' + 'name VARCHAR(30),' + 'points INT,' + - 'num_lines INT,' + - 'level INT,' + + 'num_lines INT,' + + 'level INT,' + 'isMod BOOL DEFAULT FALSE)', function (err, result) {if (err) {return}} ) @@ -20,7 +20,7 @@ connection.query( 'game VARCHAR(100),' + 'vod VARCHAR(100),' + 'lowView INT,' + - 'currView INT,' + + 'currView INT,' + 'highView INT)', function (err, result) {if (err) {return}} ) @@ -31,7 +31,7 @@ connection.query( 'commName VARCHAR(50),' + 'response VARCHAR(500),' + 'commDesc VARCHAR(500),' + - 'commUse VARCHAR(500),' + + 'commUse TEXT,' + 'level INT DEFAULT 100,' + 'cdType VARCHAR(50),' + 'cd INT)', @@ -94,34 +94,34 @@ 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 = [ @@ -141,7 +141,7 @@ var standardCommands = [ ["!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"], + ["!songrequest", null, "Allows subs to request songs in chat", "global", 10, 150, "!songrequest Enjoy the silence - Depeche Mode | !songrequest https://www.youtube.com/watch?v=aGSKrC7dGcY | !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 :)"], @@ -153,4 +153,4 @@ var standardCommands = [ ] connection.query(sql2, [standardCommands], function (err, result) {if (err) console.log(err)}) -connection.end(); \ No newline at end of file +connection.end(); diff --git a/static/css/yucibot.css b/static/css/yucibot.css index cc804ef..1396156 100644 --- a/static/css/yucibot.css +++ b/static/css/yucibot.css @@ -3,6 +3,25 @@ color: #a2a8b7; } +.commands { + background-color: rgb(45, 55, 64); + border: 1px solid gray; + padding-left: 20px; + margin-right: 20px; + margin-top: 20px; + margin-bottom: 20px; + position: relative;; + float: bottom; +} + +#subCommands { + background-color: rgb(33, 57, 80); +} + +#modCommands { + background-color: rgb(31, 45, 59); +} + .twitch { width: 1350px; } @@ -201,7 +220,7 @@ .top { position:absolute; - left:200px; + left:200px; top: 0; right:0; height: 200px; @@ -211,8 +230,8 @@ } .menu { position:absolute; - left:0; - top:100px; + left:0; + top:100px; bottom: 0px; width: 200px; background-color: #22292b; @@ -221,9 +240,9 @@ } .main { position: absolute; - left:200px; - top:100px; - right:0; + left:200px; + top:100px; + right:0; bottom:0; padding-left: 20px; background-color: #2f3a3c; @@ -243,7 +262,7 @@ margin: 0px; } -div.menu p:hover, div.login p:hover, div#logMenu p:hover { +div.menu p:hover, div.login p:hover, div#logMenu p:hover { background-color: #384447; } @@ -258,7 +277,7 @@ div.menu h3 { footer { padding: 1em; text-align: center; - position: absolute; + position: absolute; bottom: 0; } @@ -273,7 +292,7 @@ body { overflow: hidden; } -table, th, td { +.moduleTable td, th { border: 1px solid black; text-align: left; } @@ -284,4 +303,4 @@ th, td { a { color: #4995c7; -} \ No newline at end of file +} diff --git a/templates/admin/modules.html b/templates/admin/modules.html index 5a6fec6..69280c5 100644 --- a/templates/admin/modules.html +++ b/templates/admin/modules.html @@ -3,11 +3,11 @@ var socket = io.connect('<%= website %>'); function disableModule(name) { socket.emit('disableModule', name) - setTimeout(function() {window.location.reload(true)}, 100); + setTimeout(function() {window.location.reload(true)}, 100); } function enableModule(name) { socket.emit('enableModule', name) - setTimeout(function() {window.location.reload(true)}, 100); + setTimeout(function() {window.location.reload(true)}, 100); }

Modules

@@ -16,18 +16,18 @@

Enable / disable modules

You can enable or disable all the modules here.
You'll have to restart the bot for the changes to take effect.

- +
- - + + <% moduleList.forEach(function(moduleList) { %> - - + +
ModuleStateDescriptionStateDescription Change
<%= moduleList.moduleName %><%= moduleList.state %><%= moduleList.moduleDescription %><%= moduleList.state %><%= moduleList.moduleDescription %> @@ -38,4 +38,4 @@

Enable / disable modules

- \ No newline at end of file + diff --git a/templates/commands.html b/templates/commands.html index f6fb0ee..0f9a6bd 100644 --- a/templates/commands.html +++ b/templates/commands.html @@ -3,8 +3,39 @@
-

Commands test page

- +<% commands.forEach(function(commands) { %> + <% if (commands.level == 100) { %> +

+ Command: <%= commands.commName %>
+ <% if (commands.commDesc != null) { %> Description: <%= commands.commDesc %>
<% } %> + <% if (commands.response != null) { %>Response: <%= commands.response %>
<% } %> + <% if (commands.commUse != null) { %> Usage:
<%= commands.commUse %>
<% } %> + Cooldown type: <%= commands.cdType %>
+ Cooldown: <%= commands.cd %> seconds
+ User level: Everyone +

+ <% } else if (commands.level == 150) { %> +

+ Command: <%= commands.commName %>
+ <% if (commands.commDesc != null) { %> Description: <%= commands.commDesc %>
<% } %> + <% if (commands.response != null) { %>Response: <%= commands.response %>
<% } %> + <% if (commands.commUse != null) { %> Usage:
<%- commands.commUse.split("|").join("
") %>
<% } %> + Cooldown type: <%= commands.cdType %>
+ Cooldown: <%= commands.cd %> seconds
+ User level: Subscriber +

+ <% } else { %> +

+ Command: <%= commands.commName %>
+ <% if (commands.commDesc != null) { %> Description: <%= commands.commDesc %>
<% } %> + <% if (commands.response != null) { %>Response: <%= commands.response %>
<% } %> + <% if (commands.commUse != null) { %> Usage:
<%= commands.commUse %>
<% } %> + Cooldown type: <%= commands.cdType %>
+ Cooldown: <%= commands.cd %> seconds
+ User level: Moderator +

+ <% } %> +<% }) %>
- \ No newline at end of file + diff --git a/website.js b/website.js index de9817b..f01b391 100644 --- a/website.js +++ b/website.js @@ -66,15 +66,15 @@ app.all('*', function(req, res, next) { } else { if (result[0].isMod == 1) { res.locals.login = true, - res.locals.mod = true, + res.locals.mod = true, res.locals.name = req.user } else { res.locals.login = true, - res.locals.mod = false, + res.locals.mod = false, res.locals.name = req.user } }; - }); + }); } else { res.locals.login = false } @@ -170,7 +170,7 @@ app.get('/user/:id/logs', function(req, res) { if (result[0] == undefined) { res.render("error404.html"); } else { - res.render('logs.html', { + res.render('logs.html', { log: result, name: result[0].name }); @@ -179,7 +179,11 @@ app.get('/user/:id/logs', function(req, res) { }); app.get('/commands', function(req, res) { - connection.query('select * from commands', function(err, result) {res.render('commands.html')}); + connection.query('select * from commands ORDER BY level', function(err, result) { + res.render('commands.html', { + commands: result + }) + }); }); app.get('/stats', function(req, res) { @@ -240,13 +244,13 @@ app.get('/history/:id', function(req, res) { } else { connection.query('select * from songrequest where playState = 0 AND DATE_FORMAT(time,"%Y-%m-%d") = ? ORDER BY id LIMIT 1', req.params.id, function(err, result) { if (result == undefined || result[0] == undefined) { - res.render('history.html', { + res.render('history.html', { currSong: [{"title": "The songlist has finished"}], songInfo: songInfo, listDate: req.params.id }); } else { - res.render('history.html', { + res.render('history.html', { currSong: result, songInfo: songInfo, listDate: req.params.id @@ -324,7 +328,7 @@ app.get('/admin/logs', function(req, res) { log: false }); } else { - res.render('admin/adminlogs.html', { + res.render('admin/adminlogs.html', { log: result }); }; @@ -338,7 +342,7 @@ app.get('/admin/logs/login', function(req, res) { log: false }); } else { - res.render('admin/adminlogs.html', { + res.render('admin/adminlogs.html', { log: result }); }; @@ -352,7 +356,7 @@ app.get('/admin/logs/points', function(req, res) { log: false }); } else { - res.render('admin/adminlogs.html', { + res.render('admin/adminlogs.html', { log: result }); }; @@ -366,7 +370,7 @@ app.get('/admin/logs/sub', function(req, res) { log: false }); } else { - res.render('admin/adminlogs.html', { + res.render('admin/adminlogs.html', { log: result }); }; @@ -380,7 +384,7 @@ app.get('/admin/logs/timeout', function(req, res) { log: false }); } else { - res.render('admin/adminlogs.html', { + res.render('admin/adminlogs.html', { log: result }); }; @@ -389,7 +393,7 @@ app.get('/admin/logs/timeout', function(req, res) { app.get('/admin/modules', function(req, res) { connection.query('select * from module WHERE id != 1', function(err, result) { - res.render('admin/modules.html', { + res.render('admin/modules.html', { moduleList: result, website: options.identity.websiteUrl });