convert vars to const and let

develop
lub 7 years ago
parent 5d0effd8f4
commit 6186516cdb

@ -5,7 +5,7 @@ const yaml = require('js-yaml');
const config = yaml.safeLoad(fs.readFileSync('config.yaml'));
var matrixclient = sdk.createClient({
const matrixclient = sdk.createClient({
baseUrl: config.baseurl,
accessToken: config.accesstoken,
userId: config.userid
@ -20,18 +20,18 @@ var matrixclient = sdk.createClient({
});*/
var commands = {};
const commands = {};
commands['rebuild'] = {};
commands['rebuild'].regex = /^!rebuild ([a-zA-Z0-9\-]*)$/;
commands['rebuild'].usage = '!rebuild <container>';
commands['rebuild'].exec = function(args, room, event) {
var container = args[1];
let container = args[1];
matrixclient.sendNotice(room.roomId, 'rebuilding container ' + container);
console.log('sudo ./rebuild.sh ' + container);
var script = spawn('/bin/bash', ['./rebuild.sh', container]);
let script = spawn('/bin/bash', ['./rebuild.sh', container]);
script.on('close', function(exitcode) {
matrixclient.sendNotice(room.roomId, event.sender.userId + '\nrebuilt container ' + container + '\nexitcode: ' + exitcode);
});
@ -46,18 +46,18 @@ matrixclient.on('Room.timeline', function(event, room, resettimeline) {
return;
}
var body = event.getContent().body;
let body = event.getContent().body;
var bang = body.match(/^\!([a-zA-Z]*)/);
let bang = body.match(/^\!([a-zA-Z]*)/);
if(bang === null) {
return;
}
bang = bang[1];
if(commands[bang] !== undefined) {
var command = commands[bang];
let command = commands[bang];
var args = body.match(command['regex']);
let args = body.match(command['regex']);
if(args === null) {
matrixclient.sendNotice(room.roomId, 'usage: ' + command.usage);
return;