NodeJS – Steam API – 自动接受好友请求

我试图找出如何自动接受朋友的请求,因为我真的很无聊我一直在做一些东西在我开始的一个机器人。

这里有两个有用的链接:
https://github.com/seishun/node-steam/blob/master/README.md#relationships
https://github.com/seishun/node-steam/blob/master/README.md#friends

所以我一直在试图弄清楚如何使它自动接受使用这些朋友的请求。

目前有一个待处理的朋友请求,我很好奇我会如何自动接受它,甚至打印当前的朋友请求。

以下是我可以阅读@ node-steam的自述文件的“朋友”事件,看起来像。

http://puu.sh/6XznQ.png

在“朋友”事件下,它说:

The friends and groups properties now contain data (unless your friend/group list is empty). Listen for this if you want to accept/decline friend requests that came while you were offline, for example. 

我很好奇我将如何访问这两个属性? 对不起,如果这是一个愚蠢的问题。 在此先感谢,我还在学习。 :3

我已经确定我做错了,但我已经坐了一段时间了,试图弄清楚,但是我做不到。 如果有不止一个朋友的要求,我的“朋友”活动将不能正常工作,因为它需要通过所有现有的活动,但是我仍然不确定该怎么做。 编辑; 我只是试过这个:

第二个图像

它目前至less有一个朋友的请求,但它没有反应,所以我想“朋友”事件是错误的?

编辑2; 我需要使用“关系”事件,而不是“朋友”。 现在我只需要弄清楚如何查看所有当前的朋友请求。

我也发现这个枚举:

 Steam.EFriendRelationship = { None: 0, Blocked: 1, PendingInvitee: 2, // obsolete - renamed to RequestRecipient RequestRecipient: 2, Friend: 3, RequestInitiator: 4, PendingInviter: 4, // obsolete - renamed to RequestInitiator Ignored: 5, IgnoredFriend: 6, SuggestedFriend: 7, Max: 8, }; 

我不确定的是我将如何通过所有现有的朋友邀请。 使用:

 console.log(Steam.EFriendRelationship.PendingInvitee); 

返回“2”,因为这是枚举值。 我将如何获得列出的所有挂起的邀请?

回答你的第一个问题

其实我今天一直在用这个机器人写一个bot,遇到了这个问题。 我是这么做的:

 var Steam = require("steam"); var steam = new Steam.SteamClient() steam.on("friend", function(steamID, relationship) { if (relationship == Steam.EFriendRelationship.PendingInvitee) { console.log("friend request received"); steam.addFriend(steamID); console.log("friend request accepted"); } }); 

这是不言自明的,但是在收到好友请求后打印“好友请求”,添加朋友,然后打印添加好友。

编辑:

以下是如何添加机器人离线时发送的好友请求;

 var _ = require("underscore"); var addPendingFriends = function() { console.log("searching for pending friend requests..."); _.each(steam.friends, function(relationship, steamID) { if (relationship == Steam.EFriendRelationship.RequestRecipient) { steam.addFriend(steamID); console.log(steamID+" was added as a friend"); } }); console.log("finished searching"); }; 

如果我是对的,这是你在找什么? 🙂

重要提示:调用addPendingFriends(); 在webLogOn()之后,似乎steam.friends不会在login时启动。