Skip to content

Commit

Permalink
Merge branch 'development' into IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed May 2, 2024
2 parents 0e66802 + bb264ec commit 38939e3
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tf2autobot",
"version": "5.11.2",
"version": "5.12.0",
"description": "Fully automated TF2 trading bot advertising on www.backpack.tf using prices from www.prices.tf, Originally made by Nicklason.",
"main": "dist/app.js",
"scripts": {
Expand Down
11 changes: 7 additions & 4 deletions src/classes/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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 @@ -964,7 +964,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 @@ -988,8 +988,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 Expand Up @@ -1255,6 +1254,10 @@ export default class Bot {
this.listingManager.setUserID(this.userID);
}

if (this.options.steamApiKey) {
this.manager.apiKey = this.options.steamApiKey;
}

return new Promise((resolve, reject) => {
this.manager.setCookies(cookies, err => {
if (err) {
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
6 changes: 6 additions & 0 deletions src/classes/InventoryApis/InventoryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export default class InventoryApi {
return;
}

if (result?.fake_redirect === 0) {
// fake redirect caused by steam erros on the proxy's side
return callback(new Error('Received fake redirect 0'));
}

if (result && result.success && result.total_inventory_count === 0) {
// Empty inventory
callback(null, [], [], 0);
Expand Down Expand Up @@ -177,4 +182,5 @@ interface GetUserInventoryContentsResult {
more_items?: number;
total_inventory_count?: number;
success?: number;
fake_redirect?: 1 | 0;
}
2 changes: 2 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,7 @@ export default interface Options extends JsonOptions {
steamPassword?: string;
steamSharedSecret?: string;
steamIdentitySecret?: string;
steamApiKey?: string;

bptfAccessToken?: string;
bptfApiKey?: string;
Expand Down Expand Up @@ -2499,6 +2500,7 @@ export function loadOptions(options?: Options): Options {
steamPassword: getOption('steamPassword', '', String, incomingOptions),
steamSharedSecret: getOption('steamSharedSecret', '', String, incomingOptions),
steamIdentitySecret: getOption('steamIdentitySecret', '', String, incomingOptions),
steamApiKey: getOption('steamApiKey', '', String, incomingOptions),

bptfAccessToken: getOption('bptfAccessToken', '', String, incomingOptions),
bptfApiKey: getOption('bptfApiKey', '', String, incomingOptions),
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
5 changes: 2 additions & 3 deletions template.ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"STEAM_PASSWORD": "",
"STEAM_SHARED_SECRET": "",
"STEAM_IDENTITY_SECRET": "",
"STEAM_API_KEY": "",

"BPTF_ACCESS_TOKEN": "",
"BPTF_API_KEY": "",
Expand All @@ -28,9 +29,7 @@
"STEAMSUPPLY_API_KEY": "",
"STEAMAPIS_API_KEY": "",

"ADMINS": [
{ "steam": "<your steamid 64>", "discord": null }
],
"ADMINS": [{ "steam": "<your steamid 64>", "discord": null }],
"KEEP": ["<steamid of person to keep in friendslist>"],
"ITEM_STATS_WHITELIST": [],
"GROUPS": ["103582791469033930"],
Expand Down
1 change: 1 addition & 0 deletions template.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ STEAM_ACCOUNT_NAME=""
STEAM_PASSWORD=""
STEAM_SHARED_SECRET=""
STEAM_IDENTITY_SECRET=""
STEAM_API_KEY=""

BPTF_ACCESS_TOKEN=""
BPTF_API_KEY=""
Expand Down

0 comments on commit 38939e3

Please sign in to comment.