You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.8 KiB
JavaScript
71 lines
1.8 KiB
JavaScript
const spawn = require('child_process').spawn;
|
|
const sdk = require('matrix-js-sdk');
|
|
|
|
var userid = '';
|
|
var accesstoken = '';
|
|
var matrixclient = sdk.createClient({
|
|
baseUrl: 'https://imninja.net',
|
|
accessToken: accesstoken,
|
|
userId: userid
|
|
});
|
|
|
|
/*matrixclient.on('RoomMember.membership', function(event, member) {
|
|
if(member.membership === 'invite' && member.userId === userid) {
|
|
matrixclient.joinRoom(member.roomId).done(function() {
|
|
console.log('Auto-joined %s', member.roomId);
|
|
});
|
|
}
|
|
});*/
|
|
|
|
|
|
var 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];
|
|
|
|
matrixclient.sendNotice(room.roomId, 'rebuilding container ' + container);
|
|
console.log('sudo ./rebuild.sh ' + container);
|
|
|
|
var script = spawn('/bin/bash', ['./rebuild.sh', container]);
|
|
script.on('close', function(exitcode) {
|
|
matrixclient.sendNotice(room.roomId, event.sender.userId + '\nrebuilt container ' + container + '\nexitcode: ' + exitcode);
|
|
});
|
|
}
|
|
|
|
|
|
matrixclient.on('Room.timeline', function(event, room, resettimeline) {
|
|
if(resettimeline) {
|
|
return;
|
|
}
|
|
if(event.getType() !== 'm.room.message') {
|
|
return;
|
|
}
|
|
|
|
var body = event.getContent().body;
|
|
|
|
var bang = body.match(/^\!([a-zA-Z]*)/);
|
|
if(bang === null) {
|
|
return;
|
|
}
|
|
bang = bang[1];
|
|
|
|
if(commands[bang] !== undefined) {
|
|
var command = commands[bang];
|
|
|
|
var args = body.match(command['regex']);
|
|
if(args === null) {
|
|
matrixclient.sendNotice(room.roomId, 'usage: ' + command.usage);
|
|
return;
|
|
}
|
|
|
|
command.exec(args, room, event);
|
|
}
|
|
});
|
|
|
|
|
|
|
|
matrixclient.startClient();
|