|
| 1 | +import { ItemsDict, TradeOffer } from '@tf2autobot/tradeoffer-manager'; |
| 2 | +import WebhookHandler, { WebhookType } from './Webhook'; |
| 3 | +import Bot from '../../classes/Bot'; |
| 4 | +import * as t from '../tools/export'; |
| 5 | +import { getPartnerDetails } from '../DiscordWebhook/utils'; |
| 6 | + |
| 7 | +export interface TradeSummery { |
| 8 | + tradeSummery: ( |
| 9 | + offer: TradeOffer, |
| 10 | + accepted: Accepted, |
| 11 | + bot: Bot, |
| 12 | + timeTakenToComplete: number, |
| 13 | + timeTakenToProcessOrConstruct: number, |
| 14 | + timeTakenToCounterOffer: number | undefined, |
| 15 | + isOfferSent: boolean | undefined |
| 16 | + ) => void; |
| 17 | +} |
| 18 | + |
| 19 | +interface Accepted { |
| 20 | + invalidItems: string[]; |
| 21 | + disabledItems: string[]; |
| 22 | + overstocked: string[]; |
| 23 | + understocked: string[]; |
| 24 | + highValue: string[]; |
| 25 | + isMention: boolean; |
| 26 | +} |
| 27 | + |
| 28 | +export async function tradeSummery( |
| 29 | + this: WebhookHandler, |
| 30 | + offer: TradeOffer, |
| 31 | + accepted: Accepted, |
| 32 | + bot: Bot, |
| 33 | + timeTakenToComplete: number, |
| 34 | + timeTakenToProcessOrConstruct: number, |
| 35 | + timeTakenToCounterOffer: number | undefined, |
| 36 | + isOfferSent: boolean | undefined |
| 37 | +) { |
| 38 | + const value = t.valueDiff(offer); |
| 39 | + |
| 40 | + const dict = offer.data('dict') as ItemsDict; |
| 41 | + |
| 42 | + const details = await getPartnerDetails(offer, bot); |
| 43 | + |
| 44 | + const links = t.generateLinks(offer.partner.toString()); |
| 45 | + |
| 46 | + const slots = bot.tf2.backpackSlots; |
| 47 | + const autokeys = bot.handler.autokeys; |
| 48 | + const status = autokeys.getOverallStatus; |
| 49 | + |
| 50 | + const message = t.replace.specialChar(offer.message); |
| 51 | + const isDonate = t.isDonate(offer); |
| 52 | + |
| 53 | + const data = { |
| 54 | + value, |
| 55 | + links, |
| 56 | + slots, |
| 57 | + status, |
| 58 | + message, |
| 59 | + isDonate, |
| 60 | + details, |
| 61 | + dict, |
| 62 | + timeTakenToComplete, |
| 63 | + timeTakenToProcessOrConstruct, |
| 64 | + timeTakenToCounterOffer, |
| 65 | + isOfferSent |
| 66 | + }; |
| 67 | + |
| 68 | + void this.sendWebhook(WebhookType.tradeSummary, data); |
| 69 | +} |
0 commit comments