Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

Commit

Permalink
Update triggers for node-steam 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kjsmita6 committed Aug 8, 2015
1 parent ec4b17f commit 627c264
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 36 deletions.
30 changes: 23 additions & 7 deletions lib/chatBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,28 @@ if (fs.existsSync(serversFile)) {

var wcfg = { //define some extra logLevels for winston, also colors
levels: {
spam: 0, protocol: 1, silly: 2, verbose: 3, info: 4,
data: 5, warn: 6, debug: 7, error: 8, failure: 9
spam: 0,
protocol: 1,
silly: 2,
verbose: 3,
info: 4,
data: 5,
warn: 6,
debug: 7,
error: 8,
failure: 9
},
colors: {
spam:'bold', protocol:'grey', silly:'white', verbose:'cyan', info:'green',
data:'gray', warn:'yellow', debug:'blue', error:'red', failure:'rainbow'
spam:'bold',
protocol:'grey',
silly:'white',
verbose:'cyan',
info:'green',
data:'gray',
warn:'yellow',
debug:'blue',
error:'red',
failure:'rainbow'
}
}

Expand All @@ -51,7 +67,7 @@ var ChatBot = function(username, password, options) {
this.steamUser = options.user || new steam.SteamUser(this.steamClient);
this.steamFriends = options.friends || new steam.SteamFriends(this.steamClient);
this.steamTrading = options.trading || new steam.SteamTrading(this.steamClient);
this.steamWebLogon = new SteamWebLogon(that.steamClient, that.steamUser);
this.steamWebLogon = new SteamWebLogon(this.steamClient, this.steamUser);
this.steamTrade = new SteamTrade();
this.name = options.name || username;
this.username = username;
Expand Down Expand Up @@ -721,7 +737,7 @@ ChatBot.prototype._onChatStateChange = function(stateChange, chatterActedOn, ste
this.winston.info("Chatbot "+this.name+":"+this._userString(chatterActedOn) + " was kicked from " + steamChatId + " by " + this._userString(chatterActedBy));

// Kicked from chat - don't autojoin
if(chatterActedOn === this.steamClient.steamId) {
if(chatterActedOn === this.steamClient.steamID) {
this._removeChatFromAutojoin(steamChatId);
}

Expand Down Expand Up @@ -911,7 +927,7 @@ ChatBot.prototype.makeAnnouncement = function(target, head, body, source) {
res.on("data", function(chunk) {
that.winston.info("Announcement created: " + head);
if(source) {
that.steamClient.sendMessage(source, "Announcement created: " + head);
that.steamFriends.sendMessage(source, "Announcement created: " + head);
} else {
return head;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/triggers/acceptChatInviteTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ AcceptChatInviteTrigger.prototype._respondToChatInvite = function(roomId, roomNa
return false;
}
AcceptChatInviteTrigger.prototype._username = function(steamId) {
return ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? this.chatBot.steamClient.users[steamId].playerName : steamId)
return ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? this.chatBot.steamFriends.personaStates[steamId].player_name : steamId)
}

4 changes: 2 additions & 2 deletions lib/triggers/banCheckTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ BanCheckTrigger.prototype._respondToChatMessage = function(roomId, chatterId, me
}

BanCheckTrigger.prototype._displayName = function(steamId) {
if(this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) {
return this.chatBot.steamClient.users[steamId].playerName + "/"+steamId;
if(this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) {
return this.chatBot.steamFriends.personaStates[steamId].player_name + "/"+steamId;
} else {
return steamId;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/triggers/infobotTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ InfobotTrigger.prototype._respond = function(toId,userId,message,options) {
}
factoid=JSON.parse(value);
var date = new Date(factoid.time);
var who = ((that.chatBot.steamClient.users && factoid.author in that.chatBot.steamClient.users) ? (that.chatBot.steamClient.users[factoid.author].playerName + "/"+factoid.author) : "http://steamcommunity.com/profiles/"+factoid.author);
var who = ((that.chatBot.steamFriends.personaStates && factoid.author in that.chatBot.steamFriends.personaStates) ? (that.chatBot.steamFriends.personaStates[factoid.author].player_name + "/"+factoid.author) : "http://steamcommunity.com/profiles/"+factoid.author);
that._sendMessageAfterDelay(toId, factoid.word+" was last modified by " + who + " at "+date.toLocaleTimeString()+" on "+date.toDateString()+". The full JSON value for it is: \n"+value);
}});
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/triggers/ircTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ IRCRelay.prototype._respondToDisconnect = function(roomId,userId) {

// Return true if the event was eaten
IRCRelay.prototype._username = function(steamId) {
return ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? this.chatBot.steamClient.users[steamId].playerName : steamId)
return ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? this.chatBot.steamFriends.personaStates[steamId].player_name : steamId)
}
IRCRelay.prototype._tryEach = function(stuff,func) {
var that = this;
Expand Down
12 changes: 6 additions & 6 deletions lib/triggers/logTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ LogTrigger.prototype._respondToBan = function(roomId,bannedId,bannerId) {
}

LogTrigger.prototype._respondToSentMessage = function(toId, message) {
if(this.chatBot.steamClient.users && toId in this.chatBot.steamClient.users) {
this._respondToFriendMessage(this.chatBot.steamClient.steamId, "to: "+toId+"; message: "+message);
if(this.chatBot.steamFriends.personaStates && toId in this.chatBot.steamFriends.personaStates) {
this._respondToFriendMessage(this.chatBot.steamClient.steamID, "to: "+toId+"; message: "+message);
} else {
this._respondToChatMessage(toId,this.chatBot.steamClient.steamID,message);
}
Expand Down Expand Up @@ -184,8 +184,8 @@ LogTrigger.prototype._global = function(roomId, userId, message, type, actedId)
roomId:roomId,
userId:userId,
actedId:actedId,
displayName:((that.chatBot.steamClient.users && userId in that.chatBot.steamClient.users) ? (that.chatBot.steamClient.users[userId].playerName) : userId) + "",
actedName:(actedId === null ? null : ((that.chatBot.steamClient.users && actedId in that.chatBot.steamClient.users) ? (that.chatBot.steamClient.users[actedId].playerName) : actedId) + ""),
displayName:((that.chatBot.steamFriends.personaStates && userId in that.chatBot.steamFriends.personaStates) ? (that.chatBot.steamFriends.personaStates[userId].player_name) : userId) + "",
actedName:(actedId === null ? null : ((that.chatBot.steamFriends.personaStates && actedId in that.chatBot.steamFriends.personaStates) ? (that.chatBot.steamFriends.personaStates[actedId].player_name) : actedId) + ""),
message:message
}
this.logs.global.info(message,log,function(){
Expand All @@ -196,10 +196,10 @@ LogTrigger.prototype._global = function(roomId, userId, message, type, actedId)
LogTrigger.prototype._username = function(steamId) {
if(this.options.html === true) {
return '<a class="username" href="http://steamcommunity.com/profiles/'+steamId+'">'
+ ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? this.chatBot.steamClient.users[steamId].playerName : steamId)
+ ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? this.chatBot.steamFriends.personaStates[steamId].player_name : steamId)
+ '</a> ';
} else {
return ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? (this.chatBot.steamClient.users[steamId].playerName + "/"+steamId) : steamId) + " ";
return ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? (this.chatBot.steamFriends.personaStates[steamId].player_name + "/"+steamId) : steamId) + " ";
}
}
LogTrigger.prototype._message = function(message) {
Expand Down
2 changes: 1 addition & 1 deletion lib/triggers/notificationTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,5 +382,5 @@ NotificationTrigger.prototype._stripCommand = function(message, command){
}

NotificationTrigger.prototype._username = function(steamId) {
return ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? this.chatBot.steamClient.users[steamId].playerName : steamId)
return ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? this.chatBot.steamFriends.personaStates[steamId].player_name : steamId)
}
2 changes: 1 addition & 1 deletion lib/triggers/playGameTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ PlayGameTrigger.prototype._respond = function(toId, message) {
var query = this._stripCommand(message);
if (query) {
var games = query.split(" ");
this.chatBot.steamClient.gamesPlayed(games);
this.chatBot.joinGame(games[0]);
return true;
}
return false;
Expand Down
7 changes: 2 additions & 5 deletions lib/triggers/playTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ var util = require("util");
var BaseTrigger = require("./baseTrigger.js").BaseTrigger;

/*
Trigger that responds to messages using Wolfram Alpha.
command = string - a message must start with this + a space before a response will be given
appId = string - the app ID to use when creating a new client
OR
client = wolfram client - use this as the client if it is passed as an option
Trigger that attempts to play games. You can specify a single gameid, or you can specify an array of gameids separated by spaces
command = string - a message must start with this + a space before a response will be given. Defaults to !play.
*/

var PlayTrigger = function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/triggers/profileCheckTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ProfileCheckTrigger.prototype._respond = function(roomId,userId) {
try { that.winston.warn("Code " + response.statusCode + " from steam for steamid " + userId); } catch (err) { that.winston.error(err.stack) }
return;
}
that.chatBot.steamClient.getSteamLevel([userId],function(levels){
that.chatBot.steamFriends.getSteamLevel([userId],function(levels){
try {
var userInfo = body.response.players[0];
if(!userInfo.profilestate || userInfo.profilestate !== 1 || userInfo.communityvisibilitystate !== 3 || !levels[userId] || levels[userId] < 3) {
Expand Down
4 changes: 2 additions & 2 deletions lib/triggers/redditOnJoinTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ RedditOnJoinTrigger.prototype._respond = function(roomId,userToCheck) {
}

RedditOnJoinTrigger.prototype._displayName = function(steamid) {
if(this.chatBot.steamClient.users && steamid in this.chatBot.steamClient.users) {
return this.chatBot.steamClient.users[steamid].playerName + "/"+steamid;
if(this.chatBot.steamFriends.personaStates && steamid in this.chatBot.steamFriends.personaStates) {
return this.chatBot.steamFriends.personaStates[steamid].player_name + "/"+steamid;
} else {
return steamid;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/triggers/redditTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RedditTrigger.prototype._respond = function(toId, message) {
cache.put(steamid,result,that.options.cacheTime);
}
else {
that._sendMessageAfterDelay(toId, (redditinfo && redditinfo.success===false && redditinfo.errormessage ? redditinfo.errormessage : ("User " + ((that.chatBot.steamClient.users && steamid in that.chatBot.steamClient.users) ? (that.chatBot.steamClient.users[steamid].playerName + "/"+steamid) : steamid) + " is not in my system.")));
that._sendMessageAfterDelay(toId, (redditinfo && redditinfo.success===false && redditinfo.errormessage ? redditinfo.errormessage : ("User " + ((that.chatBot.steamFriends.personaStates && steamid in that.chatBot.steamFriends.personaStates) ? (that.chatBot.steamFriends.personaStates[steamid].player_name + "/"+steamid) : steamid) + " is not in my system.")));
}
});
} else {
Expand All @@ -87,8 +87,8 @@ RedditTrigger.prototype._stripCommand = function(message) {
}

RedditTrigger.prototype._displayName = function(steamid) {
if(this.chatBot.steamClient.users && steamid in this.chatBot.steamClient.users) {
return this.chatBot.steamClient.users[steamid].playerName + "/"+steamid;
if(this.chatBot.steamFriends.personaStates && steamid in this.chatBot.steamFriends.personaStates) {
return this.chatBot.steamFriends.personaStates[steamid].player_name + "/"+steamid;
} else {
return steamid;
}
Expand Down
7 changes: 3 additions & 4 deletions lib/triggers/wikiBotTrigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ WikiBotTrigger.prototype._logIn = function(toId, callback) {
}

WikiBotTrigger.prototype._redirectPage = function(toId,steamId,message) {
var whoCalled = ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? (this.chatBot.steamClient.users[steamId].playerName + "/"+steamId) : steamId);
var whoCalled = ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? (this.chatBot.steamFriends.personaStates[steamId].player_name + "/"+steamId) : steamId);
var params = message.split("||");
if(params.length < 2) {
this._sendMessageAfterDelay(toId,"You need to specify the following: \"" +this.options.commandMove+" OldName||NewName[||Summary]\"");
Expand Down Expand Up @@ -159,7 +159,7 @@ WikiBotTrigger.prototype._redirectPage = function(toId,steamId,message) {
}

WikiBotTrigger.prototype._editPage = function(toId,steamId,query) {
var whoCalled = ((this.chatBot.steamClient.users && steamId in this.chatBot.steamClient.users) ? (this.chatBot.steamClient.users[steamId].playerName + "/"+steamId) : steamId);
var whoCalled = ((this.chatBot.steamFriends.personaStates && steamId in this.chatBot.steamFriends.personaStates) ? (this.chatBot.steamFriends.personaStates[steamId].player_name + "/"+steamId) : steamId);
var lines = query.split("\n");
var summary = (lines[lines.length-1].toLowerCase().indexOf("summary: ") === 0 ? true : false);
summary = whoCalled+" is editing this page " + (summary ? "because "+lines.pop().substring(9): "");
Expand Down Expand Up @@ -208,7 +208,7 @@ WikiBotTrigger.prototype._importGames = function(toId,steamId,query) {
that._sendMessageAfterDelay(toId,"Logged in as "+username);
}
try {
var whoCalled = ((that.chatBot.steamClient.users && steamId in that.chatBot.steamClient.users) ? (that.chatBot.steamClient.users[steamId].playerName + "/"+steamId) : steamId);
var whoCalled = ((that.chatBot.steamFriends.personaStates && steamId in that.chatBot.steamFriends.personaStates) ? (that.chatBot.steamFriends.personaStates[steamId].player_name + "/"+steamId) : steamId);
for (var key in info) {
var result = that._getParsedResult(body[key], whoCalled);
if(result.success) {
Expand Down Expand Up @@ -327,4 +327,3 @@ WikiBotTrigger.prototype._getExists = function(input) {
} else { return true;
}
}

0 comments on commit 627c264

Please sign in to comment.