|
|
|
@ -1,20 +1,20 @@
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
const node_ssh = require('node-ssh');
|
|
|
|
|
const nodeSsh = require('node-ssh');
|
|
|
|
|
const sdk = require('matrix-js-sdk');
|
|
|
|
|
const yaml = require('js-yaml');
|
|
|
|
|
|
|
|
|
|
const config = yaml.safeLoad(fs.readFileSync('config.yaml'));
|
|
|
|
|
const matrixclient = sdk.createClient({
|
|
|
|
|
const matrixClient = sdk.createClient({
|
|
|
|
|
baseUrl: config.matrix.baseurl,
|
|
|
|
|
accessToken: config.matrix.accesstoken,
|
|
|
|
|
userId: config.matrix.userid
|
|
|
|
|
});
|
|
|
|
|
const ssh = new node_ssh();
|
|
|
|
|
const ssh = new nodeSsh();
|
|
|
|
|
|
|
|
|
|
// Autojoin for the bot (keep commented out when not needed to prevent abuse)
|
|
|
|
|
/*matrixclient.on('RoomMember.membership', function(event, member) {
|
|
|
|
|
/*matrixClient.on('RoomMember.membership', function(event, member) {
|
|
|
|
|
if(member.membership === 'invite' && member.userId === userid) {
|
|
|
|
|
matrixclient.joinRoom(member.roomId).done(function() {
|
|
|
|
|
matrixClient.joinRoom(member.roomId).done(function() {
|
|
|
|
|
console.log('Auto-joined %s', member.roomId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -58,20 +58,20 @@ commands['rebuild'].usage = '!rebuild <container>';
|
|
|
|
|
commands['rebuild'].exec = function(args, room, event) {
|
|
|
|
|
const container = args[1];
|
|
|
|
|
|
|
|
|
|
matrixclient.sendNotice(room.roomId, 'rebuilding container ' + container);
|
|
|
|
|
matrixClient.sendNotice(room.roomId, 'rebuilding container ' + container);
|
|
|
|
|
|
|
|
|
|
remoterun('./rebuild.sh ' + container)
|
|
|
|
|
.then(function(result) {
|
|
|
|
|
matrixclient.sendNotice(room.roomId, event.sender.userId + '\nrebuilt container ' + container);
|
|
|
|
|
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.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) {
|
|
|
|
|
if(resettimeline) {
|
|
|
|
|
matrixClient.on('Room.timeline', function(event, room, resetTimeline) {
|
|
|
|
|
if(resetTimeline) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(event.getType() !== 'm.room.message') {
|
|
|
|
@ -91,7 +91,7 @@ matrixclient.on('Room.timeline', function(event, room, resettimeline) {
|
|
|
|
|
|
|
|
|
|
const args = body.match(command.regex);
|
|
|
|
|
if(args === null) {
|
|
|
|
|
matrixclient.sendNotice(room.roomId, 'usage: ' + command.usage);
|
|
|
|
|
matrixClient.sendNotice(room.roomId, 'usage: ' + command.usage);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -101,4 +101,4 @@ matrixclient.on('Room.timeline', function(event, room, resettimeline) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
matrixclient.startClient();
|
|
|
|
|
matrixClient.startClient();
|
|
|
|
|