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

Commit

Permalink
Added commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Skhmt committed Sep 29, 2016
1 parent ec7dc9c commit d960b16
Show file tree
Hide file tree
Showing 10 changed files with 8,065 additions and 455 deletions.
2 changes: 1 addition & 1 deletion app.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="lib/jquery-3.1.0.min.js"></script>
<script src="lib/vue-2.0.0-rc5.js"></script>
<script src="lib/vue-2.0.0-rc8.js"></script>
<script src="lib/bootstrap-3.3.7.min.js"></script>
<script src="lib/velocity-1.2.3.min.js"></script>
<script src="lib/velocity.ui-5.0.4.js"></script>
Expand Down
14 changes: 14 additions & 0 deletions commands/songrequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// !songrequest

module.exports = (function () {
let store = require('../lib/store')

function run(text, username, mod, sub) {
store.emit('command:songrequest', {
text,
username,
})
}

return { type: 'static', run }
})()
90 changes: 52 additions & 38 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,71 @@
*/

// song request server
let express = require('express');
let app = express();
app.use(express.static('./public'));
app.listen(3001);

require('./view/login.js')(Vue, $);
require('./view/bot.js')(Vue, $);

let store = require('./lib/store');

// Setting the Vue view model
var vm = new Vue({
el: '#app',
data: {
loggedIn: false
},
methods: {
fadeBeforeEnter: function (el) {
$(el).velocity('fadeOut', {duration: 0});
},
fadeEnter: function (el, done) {
$(el).velocity('transition.fadeIn', {delay: 180, duration: 160}, done);
},
fadeLeave: function (el, done) {
$(el).velocity('transition.fadeOut', {duration: 160}, done);
},
let express = require('express')
let app = express()
app.use(express.static('./public'))
app.listen(3001)

let store = require('./lib/store')
store.init(window, err => {
if (err) console.error(err)
else {
require('./view/login')(Vue, $)
require('./view/bot')(Vue, $)
require('./js/commands')
setupVM()
}
});
})

function setupVM() {
// Setting the Vue view model
var vm = new Vue({
el: '#app',
data: {
loggedIn: false
},
methods: {
fadeBeforeEnter: function (el) {
$(el).velocity('fadeOut', {duration: 0})
},
fadeEnter: function (el, done) {
$(el).velocity('transition.fadeIn', {delay: 180, duration: 160}, done)
},
fadeLeave: function (el, done) {
$(el).velocity('transition.fadeOut', {duration: 160}, done)
},
}
})
}

// Utility functions

function setTitle(text) {
document.getElementByTagName('title')[0].innerHTML = `${text} &mdash; KoalaBot ${nw.App.manifest.version}`;
function setTitle (text) {
document.getElementByTagName('title')[0].innerHTML = `${text} &mdash; KoalaBot ${nw.App.manifest.version}`
}

function openExtLink(url) {
nw.Shell.openExternal(url);
function openExtLink (url) {
nw.Shell.openExternal(url)
}

function getIP() {
var os = require('os');
var interfaces = os.networkInterfaces();
var addresses = [];
function getIP () {
var os = require('os')
var interfaces = os.networkInterfaces()
var addresses = []
for (var k in interfaces) {
for (var k2 in interfaces[k]) {
var address = interfaces[k][k2];
var address = interfaces[k][k2]
if (address.family === 'IPv4' && !address.internal) {
addresses.push(address.address);
addresses.push(address.address)
}
}
}

return addresses[0];
return addresses[0]
}

function getPath () {
let execPath = ''
if (process.platform == 'win32') execPath = require('path').dirname(process.execPath) + '/'
return execPath
}
50 changes: 50 additions & 0 deletions js/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

// implement points here as a Map, send points to dynamic commands and static commands
module.exports = (function () {
const commandSymbol = '!'

let bot = require('../lib/tapic-bot')

let commandList = new Map()

let fs = require('fs')
const commandsPath = './commands/'
fs.readdir(commandsPath, function (err, files) {
if (err) console.error(err)
if (!files) console.error(err)
for (let f = 0; f < files.length; f++) {
const commandName = files[f].split('.')[0]
commandList.set(commandName, require('.' + commandsPath + files[f]))
}
})

bot.listen('message', res => {
if (res.action || res.text.substring(0,1) !== commandSymbol) return null
let textArray = res.text.split(' ')
let commandKeyword = textArray.shift().substring(1)
let text = textArray.join(' ')
if (commandList.has(commandKeyword)) {
let command = commandList.get(commandKeyword) //(text, res.from, res.mod, res.sub)
if (command.type === 'dynamic') {
runDynamicCommand(command, text, res.from, res.mod, res.sub)
}
else if (command.type === 'static') {
command.run(text, res.from, res.mod, res.sub)
}
}
})

function runDynamicCommand(command, text, username, mod, sub) {
// check permissions
// replace wildcards with the appropriate tokens
// output the string
}

// dynamicCommand = {
// type: 'dynamic',
// requireMod: true,
// requireSub: false,
// requirePoints: 0,
// action: '',
// }
})()
Loading

0 comments on commit d960b16

Please sign in to comment.