3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-23 17:45:03 +00:00

compact locked triggers

This commit is contained in:
metal 2021-09-14 14:51:22 +00:00 committed by almeidx
parent 25573b10d7
commit e52db4dcd2
No known key found for this signature in database
GPG key ID: F403F80B79353CB4
5 changed files with 14 additions and 120 deletions

View file

@ -34,8 +34,6 @@ import { UnmuteTrigger } from "./unmute";
import { WarnTrigger } from "./warn";
import { ThreadArchiveTrigger } from "./threadArchive";
import { ThreadUnarchiveTrigger } from "./threadUnarchive";
import { ThreadLockTrigger } from "./threadLock";
import { ThreadUnlockTrigger } from "./threadUnlock";
export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>> = {
any_message: AnyMessageTrigger,
@ -77,8 +75,6 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
thread_delete: ThreadDeleteTrigger,
thread_archive: ThreadArchiveTrigger,
thread_unarchive: ThreadUnarchiveTrigger,
thread_lock: ThreadLockTrigger,
thread_unlock: ThreadUnlockTrigger,
};
export const AvailableTriggers = t.type({
@ -122,6 +118,4 @@ export const AvailableTriggers = t.type({
thread_delete: ThreadDeleteTrigger.configType,
thread_archive: ThreadArchiveTrigger.configType,
thread_unarchive: ThreadUnarchiveTrigger.configType,
thread_lock: ThreadLockTrigger.configType,
thread_unlock: ThreadUnlockTrigger.configType,
});

View file

@ -15,6 +15,7 @@ interface ThreadArchiveResult {
export const ThreadArchiveTrigger = automodTrigger<ThreadArchiveResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
locked: tNullable(t.boolean),
}),
defaultConfig: {},
@ -24,6 +25,12 @@ export const ThreadArchiveTrigger = automodTrigger<ThreadArchiveResult>()({
return;
}
if (triggerConfig.locked && !context.threadChange.locked) {
return;
} else if (triggerConfig.locked === false && !context.threadChange.unlocked) {
return;
}
const thread = context.threadChange.archived;
if (triggerConfig.parent) {

View file

@ -1,57 +0,0 @@
import { Snowflake } from "discord-api-types";
import { User, Util } from "discord.js";
import * as t from "io-ts";
import { tNullable } from "../../../utils";
import { automodTrigger } from "../helpers";
interface ThreadLockResult {
matchedThreadId: Snowflake;
matchedThreadName: string;
matchedThreadParentId: Snowflake;
matchedThreadParentName: string;
matchedThreadOwner: User | undefined;
}
export const ThreadLockTrigger = automodTrigger<ThreadLockResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
defaultConfig: {},
async match({ context, triggerConfig }) {
if (!context.threadChange?.locked) {
return;
}
const thread = context.threadChange.locked;
if (triggerConfig.parent) {
const parentIds = Array.isArray(triggerConfig.parent) ? triggerConfig.parent : [triggerConfig.parent];
if (thread.parentId && !parentIds.includes(thread.parentId)) return;
}
return {
extra: {
matchedThreadId: thread.id,
matchedThreadName: thread.name,
matchedThreadParentId: thread.parentId ?? "Unknown",
matchedThreadParentName: thread.parent?.name ?? "Unknown",
matchedThreadOwner: context.user,
},
};
},
async renderMatchInformation({ matchResult }) {
const threadId = matchResult.extra.matchedThreadId;
const threadName = matchResult.extra.matchedThreadName;
const threadOwner = matchResult.extra.matchedThreadOwner;
const parentId = matchResult.extra.matchedThreadParentId;
const parentName = matchResult.extra.matchedThreadParentName;
const base = `Thread **#${threadName}** (\`${threadId}\`) has been locked in the **#${parentName}** (\`${parentId}\`) channel`;
if (threadOwner) {
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
}
return base;
},
});

View file

@ -15,6 +15,7 @@ interface ThreadUnarchiveResult {
export const ThreadUnarchiveTrigger = automodTrigger<ThreadUnarchiveResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
locked: tNullable(t.boolean),
}),
defaultConfig: {},
@ -24,6 +25,12 @@ export const ThreadUnarchiveTrigger = automodTrigger<ThreadUnarchiveResult>()({
return;
}
if (triggerConfig.locked && !context.threadChange.locked) {
return;
} else if (triggerConfig.locked === false && !context.threadChange.unlocked) {
return;
}
const thread = context.threadChange.unarchived;
if (triggerConfig.parent) {

View file

@ -1,57 +0,0 @@
import { Snowflake } from "discord-api-types";
import { User, Util } from "discord.js";
import * as t from "io-ts";
import { tNullable } from "../../../utils";
import { automodTrigger } from "../helpers";
interface ThreadUnlockResult {
matchedThreadId: Snowflake;
matchedThreadName: string;
matchedThreadParentId: Snowflake;
matchedThreadParentName: string;
matchedThreadOwner: User | undefined;
}
export const ThreadUnlockTrigger = automodTrigger<ThreadUnlockResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
defaultConfig: {},
async match({ context, triggerConfig }) {
if (!context.threadChange?.unlocked) {
return;
}
const thread = context.threadChange.unlocked;
if (triggerConfig.parent) {
const parentIds = Array.isArray(triggerConfig.parent) ? triggerConfig.parent : [triggerConfig.parent];
if (thread.parentId && !parentIds.includes(thread.parentId)) return;
}
return {
extra: {
matchedThreadId: thread.id,
matchedThreadName: thread.name,
matchedThreadParentId: thread.parentId ?? "Unknown",
matchedThreadParentName: thread.parent?.name ?? "Unknown",
matchedThreadOwner: context.user,
},
};
},
async renderMatchInformation({ matchResult }) {
const threadId = matchResult.extra.matchedThreadId;
const threadName = matchResult.extra.matchedThreadName;
const threadOwner = matchResult.extra.matchedThreadOwner;
const parentId = matchResult.extra.matchedThreadParentId;
const parentName = matchResult.extra.matchedThreadParentName;
const base = `Thread **#${threadName}** (\`${threadId}\`) has been locked in the **#${parentName}** (\`${parentId}\`) channel`;
if (threadOwner) {
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
}
return base;
},
});