-
Notifications
You must be signed in to change notification settings - Fork 4
Revise Track/Report to use a single persistent thread for each user #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
89fddc3
Add user_threads database table and model for persistent modlog threa…
vcarl 70f61b5
Refactor modLog to use persistent user threads instead of per-message…
vcarl e5dd371
Complete modLog refactor implementation and documentation
vcarl 0d0af26
Implement freestanding threads and improve message flow
vcarl 39a5182
Update Discord to 14.21
vcarl 09c0ed3
Simplify userThread model
vcarl b10e555
Fix deprecation warning
vcarl c15c426
Memory!
vcarl 3d5d9d7
Fix some "Unknown Message" logs that turned out to come from deletion…
vcarl 16633fa
Refine chat experience for updated Track command
vcarl db8db14
Replace TTL cache with database in modLog.ts
vcarl b772743
Convert escalation controls to persistent Discord.js components
vcarl 4425ec8
Handle a race condition on insertion, fix some replies
vcarl 10a0380
Fix messages not being forwarded to #mod-log
vcarl 1736c72
Delete some long/unhelpful notes
vcarl 77c1bc9
Move types and delete dead code
vcarl cc64e1d
Fix a bunch of weird edge cases
vcarl ee19da2
Fix "delete all reported messages"
vcarl 412b3ed
Add deletion tracking to prevent duplicate deletions of reported mess…
vcarl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ k8s-context | |
tsconfig.tsbuildinfo | ||
.react-router | ||
tailwind.css | ||
userInfoCache.json | ||
vite.config.ts* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
import { InteractionType, PermissionsBitField } from "discord.js"; | ||
import type { MessageComponentCommand } from "#~/helpers/discord"; | ||
import { fetchSettings, SETTINGS } from "#~/models/guilds.server"; | ||
import { deleteAllReportedForUser } from "#~/models/reportedMessages.server"; | ||
import { timeout, ban, kick, applyRestriction } from "#~/models/discord.server"; | ||
|
||
export const EscalationCommands = [ | ||
{ | ||
command: { | ||
type: InteractionType.MessageComponent, | ||
name: "escalate-delete", | ||
}, | ||
handler: async (interaction) => { | ||
await interaction.deferReply(); | ||
const reportedUserId = interaction.customId.split("|")[1]; | ||
const guildId = interaction.guildId!; | ||
|
||
// Permission check | ||
const member = await interaction.guild!.members.fetch( | ||
interaction.user.id, | ||
); | ||
if (!member.permissions.has(PermissionsBitField.Flags.ManageMessages)) { | ||
return interaction.editReply({ | ||
content: "Insufficient permissions", | ||
}); | ||
} | ||
|
||
try { | ||
const result = await deleteAllReportedForUser(reportedUserId, guildId); | ||
await interaction.editReply( | ||
`Messages deleted by ${interaction.user.username} (${result.deleted}/${result.total} successful)`, | ||
); | ||
} catch (error) { | ||
console.error("Error deleting reported messages:", error); | ||
await interaction.editReply({ | ||
content: "Failed to delete messages", | ||
}); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
command: { type: InteractionType.MessageComponent, name: "escalate-kick" }, | ||
handler: async (interaction) => { | ||
const reportedUserId = interaction.customId.split("|")[1]; | ||
const guildId = interaction.guildId!; | ||
|
||
// Get moderator role for permission check | ||
const { moderator: modRoleId } = await fetchSettings(guildId, [ | ||
SETTINGS.moderator, | ||
]); | ||
|
||
const member = interaction.member; | ||
if ( | ||
!member || | ||
(Array.isArray(member.roles) | ||
? !member.roles.includes(modRoleId) | ||
: !member.roles.cache.has(modRoleId)) | ||
) { | ||
return interaction.reply({ | ||
content: "Insufficient permissions", | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
try { | ||
const reportedMember = | ||
await interaction.guild!.members.fetch(reportedUserId); | ||
await Promise.allSettled([ | ||
kick(reportedMember), | ||
interaction.reply( | ||
`<@${reportedUserId}> kicked by ${interaction.user.username}`, | ||
), | ||
]); | ||
} catch (error) { | ||
console.error("Error kicking user:", error); | ||
await interaction.reply({ | ||
content: "Failed to kick user", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
command: { type: InteractionType.MessageComponent, name: "escalate-ban" }, | ||
handler: async (interaction) => { | ||
const reportedUserId = interaction.customId.split("|")[1]; | ||
const guildId = interaction.guildId!; | ||
|
||
// Get moderator role for permission check | ||
const { moderator: modRoleId } = await fetchSettings(guildId, [ | ||
SETTINGS.moderator, | ||
]); | ||
|
||
const member = interaction.member; | ||
if ( | ||
!member || | ||
(Array.isArray(member.roles) | ||
? !member.roles.includes(modRoleId) | ||
: !member.roles.cache.has(modRoleId)) | ||
) { | ||
return interaction.reply({ | ||
content: "Insufficient permissions", | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
try { | ||
const reportedMember = | ||
await interaction.guild!.members.fetch(reportedUserId); | ||
await Promise.allSettled([ | ||
ban(reportedMember), | ||
interaction.reply( | ||
`<@${reportedUserId}> banned by ${interaction.user.username}`, | ||
), | ||
]); | ||
} catch (error) { | ||
console.error("Error banning user:", error); | ||
await interaction.reply({ | ||
content: "Failed to ban user", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
command: { | ||
type: InteractionType.MessageComponent, | ||
name: "escalate-restrict", | ||
}, | ||
handler: async (interaction) => { | ||
const reportedUserId = interaction.customId.split("|")[1]; | ||
const guildId = interaction.guildId!; | ||
|
||
// Get moderator role for permission check | ||
const { moderator: modRoleId } = await fetchSettings(guildId, [ | ||
SETTINGS.moderator, | ||
]); | ||
|
||
const member = interaction.member; | ||
if ( | ||
!member || | ||
(Array.isArray(member.roles) | ||
? !member.roles.includes(modRoleId) | ||
: !member.roles.cache.has(modRoleId)) | ||
) { | ||
return interaction.reply({ | ||
content: "Insufficient permissions", | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
try { | ||
const reportedMember = | ||
await interaction.guild!.members.fetch(reportedUserId); | ||
await Promise.allSettled([ | ||
applyRestriction(reportedMember), | ||
interaction.reply( | ||
`<@${reportedUserId}> restricted by ${interaction.user.username}`, | ||
), | ||
]); | ||
} catch (error) { | ||
console.error("Error restricting user:", error); | ||
await interaction.reply({ | ||
content: "Failed to restrict user", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
command: { | ||
type: InteractionType.MessageComponent, | ||
name: "escalate-timeout", | ||
}, | ||
handler: async (interaction) => { | ||
const reportedUserId = interaction.customId.split("|")[1]; | ||
const guildId = interaction.guildId!; | ||
|
||
// Get moderator role for permission check | ||
const { moderator: modRoleId } = await fetchSettings(guildId, [ | ||
SETTINGS.moderator, | ||
]); | ||
|
||
const member = interaction.member; | ||
if ( | ||
!member || | ||
(Array.isArray(member.roles) | ||
? !member.roles.includes(modRoleId) | ||
: !member.roles.cache.has(modRoleId)) | ||
) { | ||
return interaction.reply({ | ||
content: "Insufficient permissions", | ||
ephemeral: true, | ||
}); | ||
} | ||
|
||
try { | ||
const reportedMember = | ||
await interaction.guild!.members.fetch(reportedUserId); | ||
await Promise.allSettled([ | ||
timeout(reportedMember), | ||
interaction.reply( | ||
`<@${reportedUserId}> timed out by ${interaction.user.username}`, | ||
), | ||
]); | ||
} catch (error) { | ||
console.error("Error timing out user:", error); | ||
await interaction.reply({ | ||
content: "Failed to timeout user", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}, | ||
|
||
{ | ||
command: { | ||
type: InteractionType.MessageComponent, | ||
name: "escalate-escalate", | ||
}, | ||
handler: async (interaction) => { | ||
const guildId = interaction.guildId!; | ||
|
||
// Get moderator role for mentions | ||
const { moderator: modRoleId } = await fetchSettings(guildId, [ | ||
SETTINGS.moderator, | ||
]); | ||
|
||
try { | ||
const member = await interaction.guild!.members.fetch( | ||
interaction.user.id, | ||
); | ||
|
||
await Promise.all([ | ||
interaction.channel && "send" in interaction.channel | ||
? interaction.channel.send( | ||
`Report escalated by <@${member.id}>, <@&${modRoleId}> please respond.`, | ||
) | ||
: Promise.resolve(), | ||
interaction.reply({ | ||
content: `Report escalated successfully`, | ||
ephemeral: true, | ||
}), | ||
]); | ||
|
||
// Note: The full escalate() function with ModResponse voting would need | ||
// more complex refactoring to work without Reacord. For now, this provides | ||
// basic escalation notification functionality. | ||
} catch (error) { | ||
console.error("Error escalating report:", error); | ||
await interaction.reply({ | ||
content: "Failed to escalate report", | ||
ephemeral: true, | ||
}); | ||
} | ||
}, | ||
}, | ||
] as Array<MessageComponentCommand>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.