|
|
@ -5,7 +5,7 @@ const sdk = require('matrix-js-sdk');
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
|
|
|
|
|
|
|
|
global.config = yaml.safeLoad(fs.readFileSync('config.yaml'));
|
|
|
|
global.config = yaml.safeLoad(fs.readFileSync('config.yaml'));
|
|
|
|
const matrixClient = sdk.createClient({
|
|
|
|
global.matrixClient = sdk.createClient({
|
|
|
|
baseUrl: config.matrix.baseurl,
|
|
|
|
baseUrl: config.matrix.baseurl,
|
|
|
|
accessToken: config.matrix.accesstoken,
|
|
|
|
accessToken: config.matrix.accesstoken,
|
|
|
|
userId: config.matrix.userid
|
|
|
|
userId: config.matrix.userid
|
|
|
@ -25,24 +25,6 @@ process.on('unhandledRejection', (reason) => {
|
|
|
|
console.log('Reason: ' + reason);
|
|
|
|
console.log('Reason: ' + reason);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const commands = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commands['rebuild'] = {};
|
|
|
|
|
|
|
|
commands['rebuild'].regex = /^!rebuild ([a-zA-Z0-9\-]*)$/;
|
|
|
|
|
|
|
|
commands['rebuild'].usage = '!rebuild <container>';
|
|
|
|
|
|
|
|
commands['rebuild'].exec = function(args, room, event) {
|
|
|
|
|
|
|
|
const container = args[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixClient.sendNotice(room.roomId, 'rebuilding container ' + container);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
remoteExec('./rebuild.sh ' + container)
|
|
|
|
|
|
|
|
.then(function(result) {
|
|
|
|
|
|
|
|
matrixClient.sendNotice(room.roomId, event.sender.userId + '\nrebuilt container ' + container);
|
|
|
|
|
|
|
|
}, function(result) {
|
|
|
|
|
|
|
|
matrixClient.sendNotice(room.roomId, event.sender.userId + '\nrebuild of container ' + container + ' failed.\ncode: ' + result.code + '\nstdout: \n```\n' + result.stdout + '```\nstderr: \n```\n' + result.stderr + '\n```');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
|
|
|
|
matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
|
|
|
@ -53,33 +35,29 @@ matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let body = event.getContent().body;
|
|
|
|
const body = event.getContent().body;
|
|
|
|
|
|
|
|
|
|
|
|
let project = body.match(/^\!([a-zA-Z]*)/);
|
|
|
|
commands.expandCommand(body, commands.projects)
|
|
|
|
if(project === null) {
|
|
|
|
.then((expansion) => {
|
|
|
|
return;
|
|
|
|
let subcommand = commands.projects[expansion.project][expansion.service][expansion.subcommand];
|
|
|
|
}
|
|
|
|
const args = expansion.args.match(subcommand.regex);
|
|
|
|
project = project[1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const command = commands[project];
|
|
|
|
if(args === null && !subcommand.regex.test(expansion.args)) {
|
|
|
|
|
|
|
|
matrixClient.sendNotice(room.roomId, 'usage: ' + subcommand.usage);
|
|
|
|
if(command !== undefined) {
|
|
|
|
|
|
|
|
const args = body.match(command.regex);
|
|
|
|
|
|
|
|
if(args === null) {
|
|
|
|
|
|
|
|
matrixClient.sendNotice(room.roomId, 'usage: ' + command.usage);
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
command.exec(args, room, event);
|
|
|
|
subcommand.exec(args, room, event);
|
|
|
|
}else{ //command not found
|
|
|
|
}, (fail) => { // command not found
|
|
|
|
let tmp = commands.fetchCommand(project, commands);
|
|
|
|
/* let tmp = commands.fetchCommand(project, commands.projects);
|
|
|
|
let suggestions = "";
|
|
|
|
let suggestions = "";
|
|
|
|
for(let i = 0; i < tmp.length; i++){
|
|
|
|
for(let i = 0; i < tmp.length; i++){
|
|
|
|
suggestions += "\n"+tmp[i];
|
|
|
|
suggestions += "\n"+tmp[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
matrixClient.sendNotice(room.roomId, 'Unrecognized command.\n' +
|
|
|
|
matrixClient.sendNotice(room.roomId, 'Unrecognized command.\n' +
|
|
|
|
'Did you mean:'+suggestions);
|
|
|
|
'Did you mean:'+suggestions);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|