Skip to content

Commit

Permalink
✨ add !offerinfo command
Browse files Browse the repository at this point in the history
  • Loading branch information
idinium96 committed Feb 14, 2021
1 parent 5e58f28 commit 97611d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/classes/Commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ export default class Commands {
void this.review.actionOnTradeCommand(steamID, message, command as ActionOnTrade);
} else if (['faccept', 'fdecline'].includes(command) && isAdmin) {
void this.review.forceAction(steamID, message, command as ForceAction);
} else if (command === 'offerinfo' && isAdmin) {
this.review.offerInfo(steamID, message);
} else if (command === 'pricecheck' && isAdmin) {
this.request.pricecheckCommand(steamID, message);
} else if (command === 'pricecheckall' && isAdmin) {
Expand Down
1 change: 1 addition & 0 deletions src/classes/Commands/sub-classes/Help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class HelpCommands {
'!version - Get the TF2Autobot version that the bot is running\n\n✨=== Manual review ===✨',
'!trades - Get a list of trade offers pending for manual review 🔍',
'!trade <offerID> - Get information about a trade',
'!offerinfo <offerID> - Get information about the offer from polldata 🔍',
'!accept <offerID> [Your Message] - Manually accept an active offer ✅🔍',
'!decline <offerID> [Your Message] - Manually decline an active offer ❌🔍',
'!faccept <offerID> [Your Message] - Force accept any failed to accept offer ✅🔂',
Expand Down
26 changes: 26 additions & 0 deletions src/classes/Commands/sub-classes/Review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,30 @@ export default class ReviewCommands {
);
}
}

offerInfo(steamID: SteamID, message: string): void {
const offerIdAndMessage = CommandParser.removeCommand(message);
const offerIdRegex = /\d+/.exec(offerIdAndMessage);

if (isNaN(+offerIdRegex) || !offerIdRegex) {
return this.bot.sendMessage(steamID, `⚠️ Missing offer id. Example: "!offerinfo 3957959294"`);
}

const offerId = offerIdRegex[0];

const state = this.bot.manager.pollData.received[offerId];
if (state === undefined) {
return this.bot.sendMessage(steamID, 'Offer does not exist. ❌');
}

try {
const offer = this.bot.manager.pollData.offerData[offerId];
const show = {};
show[offerId] = offer;

this.bot.sendMessage(steamID, '/code ' + JSON.stringify(show, null, 4));
} catch (err) {
return this.bot.sendMessage(steamID, `❌ Error getting offer #${offerId} info: ${(err as Error).message}`);
}
}
}

0 comments on commit 97611d6

Please sign in to comment.