convert vars to const and let

master
lub 7 years ago
parent 510fa3e900
commit b20439db97

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