mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 16:55:03 +00:00
add limit_per_channel
This commit is contained in:
parent
fb8b0583fb
commit
c8a68d8342
1 changed files with 16 additions and 3 deletions
|
@ -13,9 +13,12 @@ export const StartThreadAction = automodAction({
|
|||
auto_archive: tNullable(t.number),
|
||||
private: tNullable(t.boolean),
|
||||
slowmode: tNullable(tDelayString),
|
||||
limit_per_channel: tNullable(t.number),
|
||||
}),
|
||||
|
||||
defaultConfig: {},
|
||||
defaultConfig: {
|
||||
limit_per_channel: 5,
|
||||
},
|
||||
|
||||
async apply({ pluginData, contexts, actionConfig, ruleName }) {
|
||||
// check if the message still exists, we don't want to create threads for deleted messages
|
||||
|
@ -23,6 +26,17 @@ export const StartThreadAction = automodAction({
|
|||
if (!c.message || !c.user) return false;
|
||||
const channel = pluginData.guild.channels.cache.get(c.message.channel_id);
|
||||
if (channel?.type !== "GUILD_TEXT" || !channel.isText()) return false; // for some reason the typing here for channel.type defaults to ThreadChannelTypes (?)
|
||||
// check against max threads per channel
|
||||
if (actionConfig.limit_per_channel && actionConfig.limit_per_channel > 0) {
|
||||
const threadCount = [
|
||||
...channel.threads.cache
|
||||
.filter(
|
||||
tr => tr.ownerId === pluginData.client.application!.id && !tr.archived && tr.parentId === channel.id,
|
||||
)
|
||||
.keys(),
|
||||
].length; // very short line, yes yes
|
||||
if (threadCount >= actionConfig.limit_per_channel) return false;
|
||||
}
|
||||
return channel.messages.cache.has(c.message.id);
|
||||
});
|
||||
let autoArchive: ThreadAutoArchiveDuration;
|
||||
|
@ -54,11 +68,10 @@ export const StartThreadAction = automodAction({
|
|||
startMessage: !actionConfig.private ? c.message!.id : undefined,
|
||||
})
|
||||
.catch(noop);
|
||||
console.log(thread?.ownerId);
|
||||
if (actionConfig.slowmode && thread) {
|
||||
const dur = Math.ceil(Math.max(convertDelayStringToMS(actionConfig.slowmode) ?? 0, 0) / 1000);
|
||||
if (dur > 0) {
|
||||
await thread.edit({ rateLimitPerUser: dur }).catch(noop);
|
||||
await thread.setRateLimitPerUser(dur).catch(noop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue