lubs freitag gefummel

master
lub 7 years ago
parent 0ff036c4d5
commit 528985e817

@ -0,0 +1,70 @@
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();

@ -0,0 +1,3 @@
#!/bin/bash
sleep 10