This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathunbanTrigger.js
47 lines (40 loc) · 1.51 KB
/
unbanTrigger.js
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
var util = require("util");
var BaseTrigger = require("./baseTrigger.js").BaseTrigger;
/*
Trigger that tells the bot to unban someone from a groupchat. Send a steamid64.
command = string - a message must start with this + a space before a response will be given
*/
var UnbanTrigger = function() {
UnbanTrigger.super_.apply(this, arguments);
};
util.inherits(UnbanTrigger, BaseTrigger);
var type = "UnbanTrigger";
exports.triggerType = type;
exports.create = function(name, chatBot, options) {
var trigger = new UnbanTrigger(type, name, chatBot, options);
trigger.options.command = trigger.options.command || "!unban";
trigger.respectsMute = false;
return trigger;
};
// Return true if a message was sent
UnbanTrigger.prototype._respondToFriendMessage = function(userId, message) {
return this._respond(null, userId, message);
}
// Return true if a message was sent
UnbanTrigger.prototype._respondToChatMessage = function(roomId, chatterId, message) {
return this._respond(roomId, chatterId, message);
}
UnbanTrigger.prototype._respond = function(roomId, userId, message) {
var query = this._stripCommand(message);
if(query && query.params[1] && (roomId || query.params[2])) {
this.chatBot.unban(query.params[2] || roomId, query.params[1]);
return true;
}
return false;
}
UnbanTrigger.prototype._stripCommand = function(message) {
if (this.options.command && message && message.toLowerCase().indexOf(this.options.command.toLowerCase() + " ") === 0) {
return {message: message, params: message.split(" ")};
}
return null;
}