You've already forked AstralRinth
forked from didirus/AstralRinth
fix: checklist conditional message issues + MD formatting (#3989)
This commit is contained in:
@@ -80,11 +80,6 @@ export interface ConditionalMessage extends WeightedMessage {
|
||||
*/
|
||||
excludedActions?: string[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback message if conditions are not met.
|
||||
*/
|
||||
fallbackMessage?: () => Promise<typeof import('*.md?raw') | string>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,6 +141,16 @@ export interface ConditionalButtonAction extends BaseAction {
|
||||
* Different message configurations based on conditions.
|
||||
*/
|
||||
messageVariants: ConditionalMessage[]
|
||||
|
||||
/**
|
||||
* Global fallback message if no variants match their conditions.
|
||||
*/
|
||||
fallbackMessage?: () => Promise<string>
|
||||
|
||||
/**
|
||||
* The weight of the action's fallback message, used to determine the place where the message is placed in the final moderation message.
|
||||
*/
|
||||
fallbackWeight?: number
|
||||
}
|
||||
|
||||
export interface DropdownActionOption extends WeightedMessage {
|
||||
|
||||
@@ -126,6 +126,7 @@ export function findMatchingVariant(
|
||||
variants: ConditionalMessage[],
|
||||
selectedActionIds: string[],
|
||||
allValidActionIds?: string[],
|
||||
currentStageIndex?: number,
|
||||
): ConditionalMessage | null {
|
||||
for (const variant of variants) {
|
||||
const conditions = variant.conditions
|
||||
@@ -133,22 +134,33 @@ export function findMatchingVariant(
|
||||
const meetsRequired =
|
||||
!conditions.requiredActions ||
|
||||
conditions.requiredActions.every((id) => {
|
||||
if (allValidActionIds && !allValidActionIds.includes(id)) {
|
||||
let fullId = id
|
||||
if (currentStageIndex !== undefined && !id.startsWith('stage-')) {
|
||||
fullId = `stage-${currentStageIndex}-${id}`
|
||||
}
|
||||
|
||||
if (allValidActionIds && !allValidActionIds.includes(fullId)) {
|
||||
return false
|
||||
}
|
||||
return selectedActionIds.includes(id)
|
||||
return selectedActionIds.includes(fullId)
|
||||
})
|
||||
|
||||
const meetsExcluded =
|
||||
!conditions.excludedActions ||
|
||||
!conditions.excludedActions.some((id) => selectedActionIds.includes(id))
|
||||
!conditions.excludedActions.some((id) => {
|
||||
let fullId = id
|
||||
if (currentStageIndex !== undefined && !id.startsWith('stage-')) {
|
||||
fullId = `stage-${currentStageIndex}-${id}`
|
||||
}
|
||||
return selectedActionIds.includes(fullId)
|
||||
})
|
||||
|
||||
if (meetsRequired && meetsExcluded) {
|
||||
return variant
|
||||
}
|
||||
}
|
||||
|
||||
return variants.find((v) => v.fallbackMessage) || null
|
||||
return null
|
||||
}
|
||||
|
||||
export async function getActionMessage(
|
||||
|
||||
Reference in New Issue
Block a user