Reworked automod "set_slowmode" action (#441)
* initial * fixes Signed-off-by: GitHub <noreply@github.com> --------- Signed-off-by: GitHub <noreply@github.com> Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
parent
8860d4fb22
commit
d8c1a5791b
1 changed files with 9 additions and 6 deletions
|
@ -6,7 +6,7 @@ import { automodAction } from "../helpers";
|
||||||
|
|
||||||
export const SetSlowmodeAction = automodAction({
|
export const SetSlowmodeAction = automodAction({
|
||||||
configType: t.type({
|
configType: t.type({
|
||||||
channels: t.array(t.string),
|
channels: tNullable(t.array(t.string)),
|
||||||
duration: tNullable(tDelayString),
|
duration: tNullable(tDelayString),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@ -14,14 +14,17 @@ export const SetSlowmodeAction = automodAction({
|
||||||
duration: "10s",
|
duration: "10s",
|
||||||
},
|
},
|
||||||
|
|
||||||
async apply({ pluginData, actionConfig }) {
|
async apply({ pluginData, actionConfig, contexts }) {
|
||||||
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
|
const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0);
|
||||||
|
const channels: Snowflake[] = actionConfig.channels ?? [];
|
||||||
for (const channelId of actionConfig.channels) {
|
if (channels.length === 0) {
|
||||||
|
channels.push(...contexts.filter((c) => c.message?.channel_id).map((c) => c.message!.channel_id));
|
||||||
|
}
|
||||||
|
for (const channelId of channels) {
|
||||||
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
|
||||||
|
|
||||||
// Only text channels and text channels within categories support slowmodes
|
// Only text channels and text channels within categories support slowmodes
|
||||||
if (!channel || (!channel.isTextBased() && channel.type !== ChannelType.GuildCategory)) {
|
|
||||||
|
if (!channel?.isTextBased() && channel?.type !== ChannelType.GuildCategory) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue