我正在尝试弄清楚如何自动接受 friend 请求,因为我真的很无聊我一直在我开始使用的机器人上到处做一些事情。
这里有两个有用的链接:
https://github.com/seishun/node-steam/blob/master/README.md#relationships
https://github.com/seishun/node-steam/blob/master/README.md#friends
所以我一直在尝试弄清楚如何通过使用它们来让它自动接受好友请求。
目前有一个待处理的好友请求,我很好奇如何让它自动接受它,甚至打印出当前的好友请求。
这是我的“ friend ”事件,您可以阅读@node-steam 的自述文件,它看起来像。
在“ friend ”事件下,它表示以下内容:
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
我已经确定我做错了,但我已经在这里坐了很长时间,并试图弄清楚,但我做不到。如果有多个好友请求,我的“好友”事件将无法运行,因为它需要遍历所有现有的请求,但我仍然不确定我会怎么做。 编辑;我刚试过这个:
它目前至少有一个 friend 请求,但它没有对此使用react,所以我认为“ friend ”事件是错误的?
编辑2;我需要使用“关系”事件,而不是“ friend ”。现在我只需要弄清楚如何查看所有当前的好友请求。
我还发现了这个枚举:
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”,因为这是枚举的值。我如何列出所有待处理的邀请?
最佳答案
回答你的第一个问题......
实际上,我今天一直在用它编写一个机器人,但遇到了这个问题。 这是我的做法:
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 没有在登录时启动。
关于javascript - NodeJS - Steam API - 自动接受好友请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21804774/