-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
67 lines (59 loc) · 2.23 KB
/
bot.js
File metadata and controls
67 lines (59 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var c = require('child_process');
if (!process.env.token) {
console.log('Error: Specify token in environment');
process.exit(1);
}
var Botkit = require('./lib/Botkit.js');
var os = require('os');
var controller = Botkit.slackbot({
debug: false,
});
var bot = controller.spawn({
token: process.env.token
}).startRTM();
function getUID(user, callback) {
c.exec('id ' + user, function (err, response, stderr) {
if (response.includes('no such user')) { // Half assed way to check if there's a user, someone, again, please fix this if you can spare the time
callback(false); // Basically
}
else {
callback(parseInt(response.replace('uid=', '').split('(')[0])); // half-assed way to pull user id, only tested on ubuntu 14.04, someone please confirm and/or fix this :D
}
});
}
controller.hears([''],'direct_message,direct_mention',function(bot, message) {
bot.api.reactions.add({ // Add a heart cause why the hell not
timestamp: message.ts,
channel: message.channel,
name: 'heart',
},function(err, res) {
if (err) {
bot.botkit.log('Failed to add emoji reaction :(',err);
}
});
getUID(message.user, function (uid) {
if (!uid) {
// Add user
c.exec('useradd -g users -s /bin/bash -p $(echo ' + parseInt(Math.random()*999999999999999).toString(36) + ' | openssl passwd -1 -stdin) ' + message.user, function (err, stdout, stderr) {
if (err) {
bot.reply(message, err);
}
else {
console.log('shell user created:', message.user);
getUID(message.user, function (uid) {
c.exec(message.text, {uid:uid}, function (err, stdout, stderr) {
if (err) bot.reply(message, err);
else bot.reply(message, stdout);
});
});
}
});
}
else {
c.exec(message.text, {uid:uid}, function (err, stdout, stderr) {
if (err) bot.reply(message, err);
else bot.reply(message, stdout);
});
}
});
});