-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSteamUser.js
92 lines (88 loc) · 2.95 KB
/
SteamUser.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const sqlite = require("sqlite");
const dbPromise = sqlite.open("./database.sqlite", { Promise });
module.exports = class SteamUser {
constructor(steamUser) {
if (steamUser) {
const json = steamUser._json;
if (json) {
this.fromJson(json);
}
}
}
async fromJson(json) {
this.steamId = json.steamid || json.steamId;
this.communityVisibilityState =
json.communityvisibilitystate || json.communityVisibilityState;
this.profileState = json.profilestate || json.profileState;
this.personaName = json.personaname || json.personaName;
this.lastLogoff = json.lastlogoff || json.lastLogoff;
this.profileUrl = json.profileurl || json.profileUrl;
this.avatar = json.avatar;
this.avatarMedium = json.avatarmedium || json.avatarMedium;
this.avatarFull = json.avatarfull || json.avatarFull;
this.personaState = json.personastate || json.personaState;
this.realName = json.realname || json.realName;
this.primaryClanID = json.primaryclanid || json.primaryClanID;
this.timeCreated = json.timecreated || json.timeCreated;
this.personaStateFlags = json.personastateflags || json.personaStateFlags;
this.locCountryCode = json.loccountrycode || json.locCountryCode;
this.locStateCode = json.locstatecode || json.locStateCode;
this.locCityId = json.loccityid || json.locCityId;
}
// must be called with await for async access.
async load(steamId) {
try {
const db = await dbPromise;
const user = await db.get(
`
SELECT
steamId, communityVisibilityState, profileState, personaName,
lastLogoff, profileUrl, avatar, avatarMedium, avatarFull,
personaState, realName, primaryClanID, timeCreated, personaStateFlags,
locCountryCode, locStateCode, locCityId
FROM
SteamUsers
WHERE
steamId = ?`,
steamId
);
await this.fromJson(user);
} catch (err) {
console.log(err);
}
}
async save() {
try {
const db = await dbPromise;
await db.run(
`
INSERT OR REPLACE INTO
SteamUsers
(steamId, communityVisibilityState, profileState, personaName,
lastLogoff, profileUrl, avatar, avatarMedium, avatarFull,
personaState, realName, primaryClanID, timeCreated, personaStateFlags,
locCountryCode, locStateCode, locCityId)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
this.steamId,
this.communityVisibilityState,
this.profileState,
this.personaName,
this.lastLogoff,
this.profileUrl,
this.avatar,
this.avatarMedium,
this.avatarFull,
this.personaState,
this.realName,
this.primaryClanID,
this.timeCreated,
this.personaStateFlags,
this.locCountryCode,
this.locStateCode,
this.locCityId
);
} catch (err) {
console.log(err);
}
}
};