3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 02:25:01 +00:00
This commit is contained in:
metal 2021-09-14 14:37:48 +00:00 committed by almeidx
parent 6c01bb6200
commit 0f0f47a390
No known key found for this signature in database
GPG key ID: F403F80B79353CB4
8 changed files with 275 additions and 1 deletions

View file

@ -32,6 +32,10 @@ import { ThreadDeleteTrigger } from "./threadDelete";
import { UnbanTrigger } from "./unban";
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,
@ -71,6 +75,10 @@ export const availableTriggers: Record<string, AutomodTriggerBlueprint<any, any>
thread_create: ThreadCreateTrigger,
thread_delete: ThreadDeleteTrigger,
thread_archive: ThreadArchiveTrigger,
thread_unarchive: ThreadUnarchiveTrigger,
thread_lock: ThreadLockTrigger,
thread_unlock: ThreadUnlockTrigger,
};
export const AvailableTriggers = t.type({

View file

@ -0,0 +1,57 @@
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 ThreadArchiveResult {
matchedThreadId: Snowflake;
matchedThreadName: string;
matchedThreadParentId: Snowflake;
matchedThreadParentName: string;
matchedThreadOwner: User | undefined;
}
export const ThreadArchiveTrigger = automodTrigger<ThreadArchiveResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
defaultConfig: {},
async match({ context, triggerConfig }) {
if (!context.threadChange?.archived) {
return;
}
const thread = context.threadChange.archived;
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 archived in the **#${parentName}** (\`${parentId}\`) channel`;
if (threadOwner) {
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
}
return base;
},
});

View file

@ -0,0 +1,57 @@
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

@ -0,0 +1,57 @@
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 ThreadUnarchiveResult {
matchedThreadId: Snowflake;
matchedThreadName: string;
matchedThreadParentId: Snowflake;
matchedThreadParentName: string;
matchedThreadOwner: User | undefined;
}
export const ThreadUnarchiveTrigger = automodTrigger<ThreadUnarchiveResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
defaultConfig: {},
async match({ context, triggerConfig }) {
if (!context.threadChange?.unarchived) {
return;
}
const thread = context.threadChange.unarchived;
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 unarchived in the **#${parentName}** (\`${parentId}\`) channel`;
if (threadOwner) {
return `${base} by **${Util.escapeBold(threadOwner.tag)}** (\`${threadOwner.id}\`)`;
}
return base;
},
});

View file

@ -0,0 +1,57 @@
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;
},
});