Skip to content

Commit

Permalink
remove !adjustrate - too risky for future use
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Aug 2, 2020
1 parent 5291edb commit e9c5ca5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 103 deletions.
41 changes: 0 additions & 41 deletions src/classes/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ 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)',
'!relist - Perform relist if some of your listings are missing (you can run only once, then need to wait 30 minutes if you want to run it again)',
'!remove <sku=> OR <item=> - Remove a pricelist entry ➖',
'!get <sku=> OR <item=> - Get raw information about a pricelist entry',
Expand Down Expand Up @@ -143,8 +142,6 @@ 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 === 'relist' && isAdmin) {
this.relistCommand(steamID);
} else if (command === 'message') {
Expand Down Expand Up @@ -593,44 +590,6 @@ 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);
const autokeys = (this.bot.handler as MyHandler).getUserAutokeys();

let reply;
reply = '✅ Key rate adjusted to ' + new Currencies(buy) + '/' + new Currencies(sell);

if (autokeys.enabled === false) {
reply += '. Autokeys is disabled so no adjustment made on Autokeys.';
} else {
(this.bot.handler as MyHandler).refreshAutoKeys();
reply += '. Autokeys is enabled and has been automatically refreshed.';
}
this.bot.sendMessage(steamID, reply);
}

private messageCommand(steamID: SteamID, message: string): void {
const isAdmin = this.bot.isAdmin(steamID);
const parts = message.split(' ');
Expand Down
54 changes: 7 additions & 47 deletions src/classes/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,7 @@ Autokeys status:-
entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 1
Expand Down Expand Up @@ -2023,12 +2021,10 @@ Autokeys status:-
entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 0
intent: 1
} as any;
} else {
entry = {
Expand Down Expand Up @@ -2060,13 +2056,10 @@ Autokeys status:-
}

private createAutokeysBanking(userMinKeys: number, userMaxKeys: number): void {
const keyPrices = this.bot.pricelist.getKeyPrices();
const entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 2
Expand Down Expand Up @@ -2109,9 +2102,7 @@ Autokeys status:-
entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 1
Expand Down Expand Up @@ -2152,9 +2143,7 @@ Autokeys status:-
entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 0
Expand Down Expand Up @@ -2189,13 +2178,10 @@ Autokeys status:-
}

private updateAutokeysBanking(userMinKeys: number, userMaxKeys: number): void {
const keyPrices = this.bot.pricelist.getKeyPrices();
const entry = {
sku: '5021;6',
enabled: true,
autoprice: false,
buy: { keys: keyPrices.buy.keys, metal: keyPrices.buy.metal },
sell: { keys: keyPrices.sell.keys, metal: keyPrices.sell.metal },
autoprice: true,
max: userMaxKeys,
min: userMinKeys,
intent: 2
Expand Down Expand Up @@ -2224,32 +2210,6 @@ Autokeys status:-
});
}

refreshAutoKeys(): void {
const isKeysAlreadyExist = this.bot.pricelist.searchByName('Mann Co. Supply Crate Key', false);
if (isKeysAlreadyExist) {
this.bot.pricelist
.removePrice('5021;6', true)
.then(() => {
log.debug(`✅ Automatically remove Mann Co. Supply Crate Key.`);
this.isBuyingKeys = false;
this.isBankingKeys = false;
this.checkAutokeysStatus = false;
this.checkAlertOnLowPure = false;
this.alreadyUpdatedToBank = false;
this.alreadyUpdatedToBuy = false;
this.alreadyUpdatedToSell = false;
this.sleep(2000);
this.autokeys();
})
.catch(err => {
log.warn(`❌ Failed to remove Mann Co. Supply Crate Key automatically: ${err.message}`);
this.checkAutokeysStatus = true;
});
} else {
this.autokeys();
}
}

private keepMetalSupply(): void {
if (process.env.DISABLE_CRAFTING === 'true') {
return;
Expand Down
15 changes: 0 additions & 15 deletions src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,6 @@ 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 = Math.trunc(moment().valueOf() / 1000);
}
}

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

Expand Down

0 comments on commit e9c5ca5

Please sign in to comment.