Skip to content

Commit

Permalink
🔨 use AccessToken if API key is not set (temp)
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed May 2, 2024
1 parent 0cb7605 commit 4de3c2b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/classes/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export default class Bot {
this.manager = new TradeOfferManager({
steam: this.client,
community: this.community,
// useAccessToken: false, // https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/Access-Tokens
useAccessToken: !this.options.steamApiKey, // https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/wiki/Access-Tokens
language: 'en',
pollInterval: -1,
cancelTime: 15 * 60 * 1000,
Expand Down Expand Up @@ -960,7 +960,7 @@ export default class Bot {
});
},
(callback): void => {
log.info('Getting Steam API key...');
log.info('Setting cookies...');
void this.setCookies(cookies).asCallback(callback);
},
(callback): void => {
Expand All @@ -984,8 +984,7 @@ export default class Bot {
},
(callback): void => {
this.schemaManager = new SchemaManager({
apiKey: this.manager.apiKey,
updateTime: 24 * 60 * 60 * 1000,
updateTime: 1 * 60 * 60 * 1000,
lite: true
});

Expand Down
24 changes: 17 additions & 7 deletions src/classes/Friends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,26 @@ export default class Friends {

get getMaxFriends(): Promise<number> {
return new Promise((resolve, reject) => {
const params: {
steamid: string;
key?: string;
access_token?: string;
} = {
steamid: (this.bot.client.steamID === null
? this.bot.handler.getBotInfo.steamID
: this.bot.client.steamID
).getSteamID64()
};

if (this.bot.manager.apiKey) {
params.key = this.bot.manager.apiKey;
} else {
params.access_token = this.bot.manager.accessToken;
}
void axios({
url: 'https://api.steampowered.com/IPlayerService/GetBadges/v1/',
method: 'GET',
params: {
key: this.bot.manager.apiKey,
steamid: (this.bot.client.steamID === null
? this.bot.handler.getBotInfo.steamID
: this.bot.client.steamID
).getSteamID64()
}
params
})
.then(response => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
Expand Down
17 changes: 13 additions & 4 deletions src/classes/TF2Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,22 @@ export default class TF2Inventory {

private fetch(): Promise<void> {
return new Promise((resolve, reject) => {
const params: {
steamid: string;
key?: string;
access_token?: string;
} = { steamid: this.getSteamID.toString() };

if (this.manager.apiKey) {
params.key = this.manager.apiKey;
} else {
params.access_token = this.manager.accessToken;
}

void axios({
url: 'https://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/',
method: 'GET',
params: {
key: this.manager.apiKey,
steamid: this.getSteamID.toString()
}
params
})
.then(response => {
const body = response.data as GetPlayerItems;
Expand Down
2 changes: 2 additions & 0 deletions src/types/modules/@tf2autobot/tradeoffer-manager/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ declare module '@tf2autobot/tradeoffer-manager' {

apiKey: string | null;

accessToken: string | null;

pollInterval: number;

getUserInventoryContents(
Expand Down

0 comments on commit 4de3c2b

Please sign in to comment.