Skip to content

Commit

Permalink
add !adjustrate command to manually adjust keyrate
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Jul 31, 2020
1 parent b468015 commit 555536f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ The original tf2-automatic repository already have a lot of features, but some f
- automatically restart your bot on queue problem, and automatically relist if backpack.tf does not synchronized with your bot listings on Autokeys (sometimes it's set to automatically buy keys, but at backpack.tf, it's listed to sell.)
- use emojis on almost all messages
- list out every items on each offer review reasons
- New added commands: "!pure", "!time", "!delete", "!check", "!block", "!unblock", "!autokeys", "!inventory", "!craftweapon" and "!uncraftweapon" commands
- New added commands: "!pure", "!time", "!delete", "!check", "!block", "!unblock", "!autokeys", "!inventory", "!adjustrate", "!craftweapon" and "!uncraftweapon" commands
- and more to come!

## Added features
Expand Down
29 changes: 29 additions & 0 deletions src/classes/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ADMIN_COMMANDS: string[] = [
'!withdraw <name=>&<amount=> - Used to withdraw items',
'!add - Add a pricelist entry ➕',
'!update - Update a pricelist entry',
'!adjustrate buy.metal=<buying price>&sell.metal=<selling price> - Manually adjust key rate (reset on restart, self-update when key rate changes)',
'!remove <sku=> OR <item=> - Remove a pricelist entry ➖',
'!get <sku=> OR <item=> - Get raw information about a pricelist entry',
'!pricecheck <sku=> OR <item=> - Requests an item to be priced by PricesTF',
Expand Down Expand Up @@ -126,6 +127,8 @@ export = class Commands {
this.uncraftweaponCommand(steamID);
} else if (command === 'rate') {
this.rateCommand(steamID);
} else if (command === 'adjustrate' && isAdmin) {
this.adjustKeyRateCommand(steamID, message);
} else if (command === 'message') {
this.messageCommand(steamID, message);
} else if (command === 'cart') {
Expand Down Expand Up @@ -533,6 +536,32 @@ export = class Commands {
);
}

private adjustKeyRateCommand(steamID: SteamID, message: string): void {
const params = CommandParser.parseParams(CommandParser.removeCommand(message));

if (!params || (params.buy === undefined && params.sell === undefined)) {
this.bot.sendMessage(
steamID,
'❌ You must include both buy AND sell price, example - "!adjustkeyrate sell.metal=56.33&buy.metal=56.22"'
);
return;
}

if (+params.buy.metal > +params.sell.metal) {
this.bot.sendMessage(steamID, '❌ Sell price must be higher than buy price.');
return;
}

const buyKeys = +params.buy.keys || 0;
const buyMetal = +params.buy.metal || 0;
const sellKeys = +params.sell.keys || 0;
const sellMetal = +params.sell.metal || 0;
const buy = { keys: buyKeys, metal: buyMetal };
const sell = { keys: sellKeys, metal: sellMetal };

this.bot.pricelist.adjustKeyRate(buy, sell);
}

private messageCommand(steamID: SteamID, message: string): void {
const isAdmin = this.bot.isAdmin(steamID);
const parts = message.split(' ');
Expand Down
15 changes: 15 additions & 0 deletions src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ export default class Pricelist extends EventEmitter {
});
}

adjustKeyRate(buy: { keys: number; metal: number }, sell: { keys: number; metal: number }): void {
this.keyPrices = {
buy: new Currencies(buy),
sell: new Currencies(sell)
};
const entryKey = this.getPrice('5021;6');

if (entryKey !== null && entryKey.autoprice) {
// The price of a key in the pricelist can be different from keyPrices because the pricelist is not updated
entryKey.buy = new Currencies(buy);
entryKey.sell = new Currencies(sell);
entryKey.time = moment().valueOf();
}
}

private updateOldPrices(old: Entry[]): Promise<void> {
log.debug('Getting pricelist...');

Expand Down

0 comments on commit 555536f

Please sign in to comment.