Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Commit

Permalink
0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Skhmt committed Feb 23, 2016
1 parent 17b5c63 commit 2e44a2d
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 371 deletions.
20 changes: 9 additions & 11 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -830,25 +830,23 @@ <h1 class="panel-title">About </h1>
<!-- MODULES -->
<div class="tab-pane" id="tab-modules">
<div class="row-fluid">
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Modules Loaded: </h2>
</div>
<ul class="list-group scroll" id="moduleListNames">
</ul>
<div class="col-sm-12">
<div class="panel panel-default" id="moduleListCommands">

</div>
</div>
<div class="col-sm-4">
</div>
<div class="row-fluid">
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Module Commands: </h2>
<h2 class="panel-title">Modules Loaded: </h2>
</div>
<ul class="list-group scroll" id="moduleListCommands">
<ul class="list-group scroll" id="moduleListNames">
</ul>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Module Hotkeys: </h2>
Expand Down
10 changes: 5 additions & 5 deletions src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function updateFollowers() {
}

fs.appendFile( `${execPath}txt/follow-session.txt`, `${tempUser}\r\n` );
fs.writeFile( `${execPath}txt/follow-recent.txt`, `${tempHost}` );
fs.writeFile( `${execPath}txt/follow-recent.txt`, `${tempUser}` );
}
}
}
Expand All @@ -240,9 +240,9 @@ function subNotify(message) {

var msgArray = message.split(" ");

if ( msgArray[1] != "viewers" ) { // name just subscribed or name subscribed for 13 months in a row
fs.appendFile( `${execPath}txt/sub-session.txt`, `${tempUser}\r\n` );
fs.writeFile( `${execPath}txt/sub-recent.txt`, `${tempHost}` );
if ( msgArray[1] != "viewers" ) { // "name just subscribed" or "name subscribed for 13 months in a row"
fs.appendFile( `${execPath}txt/sub-session.txt`, `${msgArray[0]}\r\n` );
fs.writeFile( `${execPath}txt/sub-recent.txt`, `${msgArray[0]}` );
}

if ( msgArray[1] === "just" ) { // "name just subscribed!"
Expand Down Expand Up @@ -271,7 +271,7 @@ function subNotify(message) {
output = output.replace( /%months%/g, msgArray[3] );
cmdSay( output );
}

$("#hosts").append( `${getTimeStamp()} Sub: ${msgArray[0]} x${msgArray[3]} <br>` );
} else { // "13 viewers resubscribed while you were away!"
// nothing
}
Expand Down
102 changes: 84 additions & 18 deletions src/js/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @overview The API for use with KoalaBot modules
*/

var moduleCommands = [];

function apiSetup() {
// Checking for mods folder, creating if not found
try { fs.accessSync( `${execPath}mods` ); }
Expand All @@ -46,21 +48,72 @@ function apiSetup() {
* The function will be given these parameters: params (array), from (string), mod (boolean), subscriber (boolean)
* @param {String} keyword - The !command a user types in
* @param {String} functionName - What function to call.
* @return {Boolean} True if success, false if fail
* @param {String} rbac - Role-based access control. Choose from: off, all, reg, sub, mod, or bot. Off disables the
* command, even for the streamer. All is self explanatory. Reg is for regulars and above (sub, mod, bot).
* Sub is for subscribers and above (mod, bot). Mod is for moderators and above (bot).
* Bot is for the bot itself AND the streamer.
* @param {String} desc - short description of the command
* @return {boolean} True if success, false if fail
*/
function apiAddCmd(keyword, functionName, rbac, desc) {
try {
cmdList.push({ cmd: keyword.toLowerCase(), func: functionName, rbac: rbac });
$("#moduleListCommands").append(`
<li class="list-group-item">
${cmdSettings.symbol} ${keyword.toLowerCase()} - ${rbac}
</li>`);
var keylc = keyword.toLowerCase();
cmdList.push({ cmd: keylc, func: functionName, rbac: rbac });
moduleCommands[keylc] = { rbac: rbac, desc: desc };
apiRefreshModuleCommands();
return true;
} catch (e) {
return false;
}
}

/**
* Refreshes the module command list
*/

function apiRefreshModuleCommands() {
var output = `
<div class="panel-heading"><h2 class="panel-title">Module Commands: </h2></div>
<table class="table table-striped table-hover table-condensed">
<tr>
<th>Command</th>
<th>Access</th>
<th>Description</th>
</tr>`;

var moduleKeys = Object.keys(moduleCommands);
for (var i = 0; i < moduleKeys.length; i++) {
var keyword = moduleKeys[i];
output += `<tr>
<td>${keyword}</td>
<td>${moduleCommands[keyword].rbac}</td>
<td>${moduleCommands[keyword].desc}</td>
</tr>`;
}
output += `</table>`;

$("#moduleListCommands").html( output );
}

/**
* Changes the access control of a module command
* @param {String} keyword - the keyword to change
* @param {String} rbac - the access control to set it to
* @returns {boolean} - true if success, false if not found
*/
function apiChangeRBAC(keyword, rbac) {
var keylc = keyword.toLowerCase();
for (var i = 0; i < cmdList.length; i++) {
if (cmdList[i].cmd === keylc) {
cmdList[i].rbac = rbac;
moduleCommands[keylc].rbac = rbac;
apiRefreshModuleCommands();
return true;
}
}
return false;
}

/**
* Adds a module to the dropdown and creates a page.
* If the module only adds commands and doesn't require a user interface, this doesn't need to be used.
Expand Down Expand Up @@ -142,11 +195,11 @@ function apiGetPointsUnit() {
* @return {integer} null if not found, otherwise the amount of points of the user
*/
function apiGetPoints(username) {
var index = getPointIndex(username);
if ( index == -1 ) {
var usernameLC = username.toLowerCase();
if ( !pointsSettings.users[usernameLC] ) {
return null;
}
return pointsSettings.users[index].currentPoints;
return pointsSettings.users[usernameLC].currentPoints;
}

/**
Expand All @@ -156,13 +209,13 @@ function apiGetPoints(username) {
* @return {integer} null if not found, otherwise the amount of points of the user
*/
function apiSetPoints(username, points) {
var index = getPointIndex(username);
if ( index == -1 ) {
var usernameLC = username.toLowerCase();
if ( !pointsSettings.users[usernameLC] ) {
return null;
}
pointsSettings.users[index].currentPoints = parseInt( points, 10 );
pointsSettings.users[usernameLC].currentPoints = parseInt( points, 10 );
drawList();
return pointsSettings.users[index].currentPoints;
return pointsSettings.users[usernameLC].currentPoints;
}

/**
Expand All @@ -172,14 +225,27 @@ function apiSetPoints(username, points) {
* @return {integer} null if not found, otherwise the amount of points of the user
*/
function apiModPoints(username, points) {
var index = getPointIndex(username);
if ( index == -1 ) {
var usernameLC = username.toLowerCase();
if ( !pointsSettings.users[usernameLC] ) {
return null;
}
pointsSettings.users[index].currentPoints += parseInt( points, 10 );
pointsSettings.users[usernameLC].currentPoints += parseInt( points, 10 );

drawList();
return pointsSettings.users[index].currentPoints;
return pointsSettings.users[usernameLC].currentPoints;
}

/**
* Gets the number of minutes a user has been in the stream while the bot is also in the stream.
* @param {String} username - case insensitive
* @return {integer} null if not found, otherwise the amount of minutes the user has been in the stream
*/
function apiGetMinutes(username) {
var usernameLC = username.toLowerCase();
if ( !pointsSettings.users[usernameLC] ) {
return null;
}
return pointsSettings.users[usernameLC].totalPoints;
}

/**
Expand Down Expand Up @@ -218,7 +284,7 @@ function apiAppendFile(filename, text) {
* To save an object, do something like: apiWriteFile( "modExampleSettings.ini", JSON.stringify( modExampleSettings ) );
* @param {String} filename - case sensitive, the path to the \mods\ directory is included
* @param {String} text - what to make the contents of the file
* @return {Boolean} true if success, false if fail
* @return {boolean} true if success, false if fail
*/
function apiWriteFile(filename, text) {
try {
Expand Down
Loading

0 comments on commit 2e44a2d

Please sign in to comment.