-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam.js
60 lines (52 loc) · 1.6 KB
/
steam.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
'use strict';
const SteamUser = require('steam-user');
const Bobase = require('./lib/Bobase');
const Database = require('./lib/Database');
class SteamApp extends Bobase {
constructor() {
super('steamapp');
this.db = new Database(this.config.mongodb);
this.appid = this.config.steam.appid;
this.client = new SteamUser(null, { enablePicsCache: true, changelistUpdateInterval: 1000 });
this.setupListener();
}
async insertApp(data) {
this.debug('Insert App');
try {
const res = await this.db.insertOne('steamapp', data);
this.log.info(`Insert successful (ID: ${res.insertedId})`);
this.rc.publish('steamapp', res.insertedId.toString());
} catch (err) {
if (err.name !== 'MongoError' || !err.message.match(/^E11000/)) {
this.log.error(err);
} else {
this.debug(`Changenumber ${data.changenumber} already exists`);
}
}
}
setupListener() {
this.client.on('loggedOn', () => {
this.log.info('Logged On');
this.client.getProductInfo([this.appid], [], (apps) => {
this.insertApp(apps[this.appid]);
});
});
this.client.on('changelist', (changenumber) => {
this.log.verbose('Changelist', changenumber);
});
this.client.on('appUpdate', (appid, data) => {
this.log.verbose('AppUpdate', appid);
if (appid === this.appid) {
this.insertApp(data);
}
});
}
async start() {
this.debug('Connecting to MongoDB ...');
await this.db.connect();
this.debug('Connecting to Steam ...');
this.client.logOn();
}
}
const steam = new SteamApp();
steam.start();