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 pathsteamrepOnJoinTrigger.js
61 lines (54 loc) · 2.09 KB
/
steamrepOnJoinTrigger.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var util = require("util");
var request = require("request");
var BaseTrigger = require("./baseTrigger.js").BaseTrigger;
/*
Trigger that automatically looks up users on steamrep when they join.
whoToTell = If defined, tell this person when a scammer joins. Otherwise report to the channel.
*/
var SteamrepOnJoinTrigger = function() {
SteamrepOnJoinTrigger.super_.apply(this, arguments);
};
util.inherits(SteamrepOnJoinTrigger, BaseTrigger);
var type = "SteamrepOnJoinTrigger";
exports.triggerType = type;
exports.create = function(name, chatBot, options) {
var trigger = new SteamrepOnJoinTrigger(type, name, chatBot, options);
trigger.respectsMute = false;
trigger.allowMessageTriggerAfterResponse = true;
return trigger;
};
SteamrepOnJoinTrigger.prototype._respondToEnteredMessage = function(roomId, userId) {
return this._respond(roomId,userId);
}
SteamrepOnJoinTrigger.prototype._respond = function(roomId,userToCheck) {
var steamid = ""+userToCheck+"";
if (steamid) {
var that = this;
var steamrep={};
that.winston.info(that.chatBot.name+"/"+that.name+": Checking steamrep.com for " + steamid);
var params = {
method:"GET", encoding:"utf8", json:true, followAllRedirects:true,
uri:"http://steamrep.com/api/beta/reputation/"+steamid+"?json=1&extended=1"
}
request.get(params, function(error, response, body) {
if (error) {
var err = response && "Code "+response.statusCode || error;
that.winston.warn(that.chatBot.name+"/"+that.name+": " + err + " from steamrep for " + steamid);
return;
}
var result = body && body.steamrep && that._getParsedResult(body.steamrep) || null;
if (result) {
that._sendMessageAfterDelay((that.options.whoToTell ? that.options.whoToTell : roomId), result);
}
});
return true;
}
return false;
}
SteamrepOnJoinTrigger.prototype._getParsedResult = function(data) {
if(data.flags.status==="exists" && (data.reputation.toLowerCase().indexOf("scammer") >= 0)) {
return data.displayname + " is listed as a SCAMMER on steamrep!"
+" For more information, please visit http://steamrep.com/profiles/"+data.steamID64;
}
return null;
}