Skip to content

Commit

Permalink
🔀 Merge pull request #1781 from juniorISO69960/master
Browse files Browse the repository at this point in the history
Add an option for denying trades with items on both sides of the trade.
  • Loading branch information
idinium96 authored Nov 4, 2024
2 parents 06dd5a0 + 79eb244 commit c084063
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/classes/DiscordWebhook/sendTradeDeclined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default async function sendTradeDeclined(
const declinedDescription = declined.reasonDescription;
const declinedTradeSummary: Webhook = {
username: optDW.displayName || botInfo.name,
avatar_url: optDW.avatarURL || optDW.avatarURL,
avatar_url: optDW.avatarURL || botInfo.avatarURL,
content: '',
embeds: [
{
Expand Down
14 changes: 14 additions & 0 deletions src/classes/MyHandler/MyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,20 @@ export default class MyHandler extends Handler {
};
}

// Check if the offer has items on both sides
if (
!opt.miscSettings.itemsOnBothSides.enable &&
exchange['our'].contains.items &&
exchange['their'].contains.items
) {
offer.log('info', 'offer has items on both sides');
return {
action: 'decline',
reason: 'CONTAINS_ITEMS_ON_BOTH_SIDES',
meta: isContainsHighValue ? { highValue: highValueMeta } : undefined
};
}

const itemsToGiveCount = offer.itemsToGive.length;
const itemsToReceiveCount = offer.itemsToReceive.length;

Expand Down
3 changes: 3 additions & 0 deletions src/classes/MyHandler/offer/notify/declined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export default function declined(offer: TradeOffer, bot: Bot): void {
reply = custom
? custom
: declined + ' because the offer sent contains Mann Co. Supply Crate Key on both sides.';
} else if (offerReason.reason === 'CONTAINS_ITEMS_ON_BOTH_SIDES') {
const custom = opt.customMessage.decline.containsItemsOnBothSides;
reply = custom ? custom : declined + ' because the offer sent contains items on both sides.';
} else {
//
const custom = opt.customMessage.decline.general;
Expand Down
8 changes: 7 additions & 1 deletion src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const DEFAULTS: JsonOptions = {
enable: true,
withUncraft: true
},
itemsOnBothSides: {
enable: true
},
checkUses: {
duel: true,
noiseMaker: true
Expand Down Expand Up @@ -631,7 +634,8 @@ export const DEFAULTS: JsonOptions = {
failedToCounter: '',
takingItemsWithIntentBuy: '',
givingItemsWithIntentSell: '',
containsKeysOnBothSides: ''
containsKeysOnBothSides: '',
containsItemsOnBothSides: ''
},
accepted: {
automatic: {
Expand Down Expand Up @@ -1213,6 +1217,7 @@ interface MiscSettings {
sendGroupInvite?: OnlyEnable;
skipItemsInTrade?: OnlyEnable;
weaponsAsCurrency?: WeaponsAsCurrency;
itemsOnBothSides?: OnlyEnable;
checkUses?: CheckUses;
game?: Game;
alwaysRemoveItemAttributes?: AlwaysRemoveItemAttributes;
Expand Down Expand Up @@ -1770,6 +1775,7 @@ interface DeclineNote {
takingItemsWithIntentBuy?: string;
givingItemsWithIntentSell?: string;
containsKeysOnBothSides?: string;
containsItemsOnBothSides?: string;
}

interface AcceptedNote {
Expand Down
16 changes: 15 additions & 1 deletion src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,16 @@ export const optionsSchema: jsonschema.Schema = {
required: ['enable', 'withUncraft'],
additionalProperties: false
},
itemsOnBothSides: {
type: 'object',
properties: {
enable: {
type: 'boolean'
}
},
required: ['enable'],
additionalProperties: false
},
checkUses: {
type: 'object',
properties: {
Expand Down Expand Up @@ -1869,6 +1879,9 @@ export const optionsSchema: jsonschema.Schema = {
},
containsKeysOnBothSides: {
type: 'string'
},
containsItemsOnBothSides: {
type: 'string'
}
},
required: [
Expand All @@ -1889,7 +1902,8 @@ export const optionsSchema: jsonschema.Schema = {
'failedToCounter',
'takingItemsWithIntentBuy',
'givingItemsWithIntentSell',
'containsKeysOnBothSides'
'containsKeysOnBothSides',
'containsItemsOnBothSides'
],
additionalProperties: false
},
Expand Down

0 comments on commit c084063

Please sign in to comment.