-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmyBotMgr.js
More file actions
executable file
·73 lines (66 loc) · 2.73 KB
/
myBotMgr.js
File metadata and controls
executable file
·73 lines (66 loc) · 2.73 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
68
69
70
71
72
73
/**
* @file Defines Admin functions for Spark
* @author guillain guillain@gmail.com
* @license GPL-3.0
*/
// Load config
var config = require('./config');
exports.help = function(bot){
var help = '**Bot Manager** \n\n';
help += '_Description_ : Provide helpful functions to manage bot, application and user Spark accounts \n\n';
help += '_Commands_ : @ [botmgr|bm] [list|delete] [webhook|room] [id]* \n\n';
help += '_Room commands_ \n\n';
help += '* @ botmgr list room \n\n';
help += '* @ bm delete room [id] \n\n';
help += '_Webhook commands_ \n\n';
help += '* @ botmgr list webhook \n\n';
help += '* @ bm delete webhook [id] \n\n';
bot.say(help);
}
exports.botMgr = function (bot, trigger) {
var tosay = '';
var Spark = require('node-sparky');
var spark = new Spark({ token: config.token });
var helpMsg = 'Argument missing, try **@ bm help** \n';
// Remove the first two args
trigger.args.splice(0,2);
if (/help/i.test(trigger.args['0'])) { module.exports.help(bot); }
else if (trigger.args.length == 0) { tosay = helpMsg; }
else {
var action = trigger.args['0'];
var target = trigger.args['1'];
var id = trigger.args['2'];
console.log('action:' + action + ', target:' + target + ', id:' + id);
if (target == 'room' && action == 'list') {
tosay += "**Room listing**\n";
spark.roomsGet()
.then(function(rooms) { rooms.forEach(function(room) { bot.say('* ' + room.title + ', id:' + room.id + '\n'); }); })
.catch(function(err) { bot.say('* Error during rooms listing'); console.log(err); });
}
if (target == 'room' && action == 'delete') {
if (trigger.args.length < 3) { tosay = helpMsg; }
else if (trigger.args.length == 3) { tosay = 'You must be admin \n'; }
else {
spark.roomRemove(id)
.then(function(rooms) { bot.say('Room deleted \n'); })
.catch(function(err) { bot.say('* Error during room delete'); console.log(err); });
}
}
if (target == 'webhook' && action == 'list') {
tosay += "**Webhook listing**\n";
spark.webhooksGet()
.then(function(webhooks) { webhooks.forEach(function(webhook) { bot.say('* ' + webhook.name + ', id:' + webhook.id + '\n'); } ); })
.catch(function(err) { bot.say('* Error during webhooks listing'); console.log(err); });
}
if (target == 'webhook' && action == 'delete') {
if (trigger.args.length < 3) { tosay = helpMsg; }
else if (trigger.args.length == 3) { tosay = 'You must be admin \n'; }
else {
spark.webhookRemove(id)
.then(function(rooms) { bot.say('Webhook deleted \n'); })
.catch(function(err) { bot.say('* Error during room delete'); console.log(err); });
}
}
}
bot.say(tosay);
}