-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.js
57 lines (48 loc) · 2 KB
/
example.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
var fs = require('fs');
var Steam = require('steam-fork');
// if we've saved a server list, use it
if (fs.existsSync('servers')) {
Steam.servers = JSON.parse(fs.readFileSync('servers'));
}
var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);
var steamFriends = new Steam.SteamFriends(steamClient);
steamClient.connect();
steamClient.on('connected', function() {
steamUser.logOn({
account_name: 'username',
password: 'password'
});
});
steamClient.on('logOnResponse', function(logonResp) {
if (logonResp.eresult == Steam.EResult.OK) {
console.log('Logged in!');
steamFriends.setPersonaState(Steam.EPersonaState.Online); // to display your bot's status as "Online"
steamFriends.setPersonaName('Haruhi'); // to change its nickname
steamFriends.joinChat('103582791431621417'); // the group's SteamID as a string
}
});
steamClient.on('servers', function(servers) {
fs.writeFileSync('servers', JSON.stringify(servers));
});
steamFriends.on('chatInvite', function(chatRoomID, chatRoomName, patronID) {
console.log('Got an invite to ' + chatRoomName + ' from ' + steamFriends.personaStates[patronID].player_name);
steamFriends.joinChat(chatRoomID); // autojoin on invite
});
steamFriends.on('message', function(source, message, type, chatter) {
// respond to both chat room and private messages
console.log('Received message: ' + message);
if (message == 'ping') {
steamFriends.sendMessage(source, 'pong', Steam.EChatEntryType.ChatMsg); // ChatMsg by default
}
});
steamFriends.on('chatStateChange', function(stateChange, chatterActedOn, steamIdChat, chatterActedBy) {
if (stateChange == Steam.EChatMemberStateChange.Kicked && chatterActedOn == steamClient.steamID) {
steamFriends.joinChat(steamIdChat); // autorejoin!
}
});
steamFriends.on('clanState', function(clanState) {
if (clanState.announcements.length) {
console.log('Group with SteamID ' + clanState.steamid_clan + ' has posted ' + clanState.announcements[0].headline);
}
});