feat(moderation): appeals (6c) + Discord reversal on approve (6d)
Players whose linked Discord identity was banned or muted can now submit an appeal from the portal and track it; staff get a queue in the admin moderation section to claim and resolve (approve/deny) appeals. Approving a ban/mute appeal best-effort asks the Discord bot to reverse the action (unban / clear timeout) via the internal API and posts a mod-log embed; a down bot never fails the resolution (reversal_status is recorded). - Schema: new server-owned `appeals` table (no cross-owner FK to mod_actions; existence validated in app code). - Server: model/appeals/* + player appeals controller (submit/mine/ eligible/withdraw) and admin queue handlers (list/claim/resolve/ per-user) under the existing admin+moderator gate; one-active-appeal enforced app-side; eligibility keyed on the caller's linked Discord id. - 6d: bot POST /internal/mod-reverse (+ modLog.postReversal) and server botInternalClient.reverseModAction, wired into resolve(). - Client: admin Appeals queue + resolve modal, ModerationUser appeals tab, player Appeals page (submit/withdraw), nav + routes + api methods. - Docs: swagger annotations + component schemas, regenerated output. - Tests: appeals controller + pure suites (server npm test 224 green). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XmHdsbnLzDMAVQkAoTQSBe
This commit is contained in:
@@ -43,6 +43,34 @@ async function record({ client, guildId, actionType, target, staffUser, reason,
|
||||
}
|
||||
}
|
||||
|
||||
// Post an "appeal approved → action reversed" embed to the mod-log channel.
|
||||
// Unlike record() this NEVER inserts a mod_actions row — the reversal is an
|
||||
// out-of-band correction driven by the site's appeals flow, not a new staff
|
||||
// action. Best-effort: a missing channel or send failure is logged, not thrown.
|
||||
async function postReversal({ client, guildId, actionType, discordUserId, appealId }) {
|
||||
try {
|
||||
const channelId = await guildConfig.getModLogChannelId(guildId)
|
||||
if (!channelId) return
|
||||
const channel = await client.channels.fetch(channelId)
|
||||
if (!channel || !channel.isTextBased()) return
|
||||
|
||||
const reversed = actionType === 'ban' ? 'Ban lifted (unbanned)' : 'Mute cleared (timeout removed)'
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0x88c0a0)
|
||||
.setTitle('APPEAL APPROVED')
|
||||
.addFields(
|
||||
{ name: 'Action reversed', value: reversed, inline: true },
|
||||
{ name: 'Target id', value: `${discordUserId}`, inline: true },
|
||||
{ name: 'Appeal', value: `#${appealId}`, inline: true },
|
||||
)
|
||||
.setTimestamp()
|
||||
|
||||
await channel.send({ embeds: [embed] })
|
||||
} catch (err) {
|
||||
log.warn('failed to post appeal-reversal embed', { message: err.message })
|
||||
}
|
||||
}
|
||||
|
||||
function formatDuration(seconds) {
|
||||
if (seconds % 86400 === 0) return `${seconds / 86400}d`
|
||||
if (seconds % 3600 === 0) return `${seconds / 3600}h`
|
||||
@@ -50,4 +78,4 @@ function formatDuration(seconds) {
|
||||
return `${seconds}s`
|
||||
}
|
||||
|
||||
module.exports = { record }
|
||||
module.exports = { record, postReversal }
|
||||
|
||||
Reference in New Issue
Block a user