mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-11 13:07:20 +00:00
remove config in favour of overrides
This commit is contained in:
parent
11a4f30996
commit
a9351d07cd
6 changed files with 23 additions and 61 deletions
|
@ -25,23 +25,6 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
|
||||||
this.toBePermanent = new Set();
|
this.toBePermanent = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
public msgToSavedMessage(message: Message): SavedMessage {
|
|
||||||
const postedAt = moment.utc(message.createdTimestamp, "x").format("YYYY-MM-DD HH:mm:ss");
|
|
||||||
|
|
||||||
return {
|
|
||||||
data: this.msgToSavedMessageData(message),
|
|
||||||
id: message.id,
|
|
||||||
guild_id: (message.channel as GuildChannel).guildId,
|
|
||||||
channel_id: message.channelId,
|
|
||||||
user_id: message.author.id,
|
|
||||||
is_bot: message.author.bot,
|
|
||||||
posted_at: postedAt,
|
|
||||||
// @ts-expect-error
|
|
||||||
deleted_at: null,
|
|
||||||
is_permanent: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected msgToSavedMessageData(msg: Message): ISavedMessageData {
|
protected msgToSavedMessageData(msg: Message): ISavedMessageData {
|
||||||
const data: ISavedMessageData = {
|
const data: ISavedMessageData = {
|
||||||
author: {
|
author: {
|
||||||
|
|
|
@ -5,28 +5,18 @@ import { AutomodContext, AutomodPluginType } from "../types";
|
||||||
export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginType>()({
|
export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginType>()({
|
||||||
event: "threadCreate",
|
event: "threadCreate",
|
||||||
async listener({ pluginData, args: { thread } }) {
|
async listener({ pluginData, args: { thread } }) {
|
||||||
const user = thread.ownerId ? await pluginData.client.users.fetch(thread.ownerId).catch(() => void 0) : void 0;
|
const user = thread.ownerId
|
||||||
|
? await pluginData.client.users.fetch(thread.ownerId).catch(() => undefined)
|
||||||
|
: undefined;
|
||||||
const context: AutomodContext = {
|
const context: AutomodContext = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
threadChange: {
|
threadChange: {
|
||||||
created: thread,
|
created: thread,
|
||||||
},
|
},
|
||||||
user,
|
user,
|
||||||
|
channel: thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is a hack to make this trigger compatible with the reply action
|
|
||||||
const sourceChannel = thread.parent ?? pluginData.client.channels.cache.find((c) => c.id === thread.parentId);
|
|
||||||
if (sourceChannel?.isText()) {
|
|
||||||
const sourceMessage = sourceChannel.messages.cache.find(
|
|
||||||
(m) => m.thread?.id === thread.id || m.reference?.channelId === thread.id,
|
|
||||||
);
|
|
||||||
if (sourceMessage) {
|
|
||||||
const savedMessage = pluginData.state.savedMessages.msgToSavedMessage(sourceMessage);
|
|
||||||
savedMessage.channel_id = thread.id;
|
|
||||||
context.message = savedMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginData.state.queue.add(() => {
|
pluginData.state.queue.add(() => {
|
||||||
runAutomod(pluginData, context);
|
runAutomod(pluginData, context);
|
||||||
});
|
});
|
||||||
|
@ -36,7 +26,9 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
|
||||||
export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginType>()({
|
export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginType>()({
|
||||||
event: "threadDelete",
|
event: "threadDelete",
|
||||||
async listener({ pluginData, args: { thread } }) {
|
async listener({ pluginData, args: { thread } }) {
|
||||||
const user = thread.ownerId ? await pluginData.client.users.fetch(thread.ownerId).catch(() => void 0) : void 0;
|
const user = thread.ownerId
|
||||||
|
? await pluginData.client.users.fetch(thread.ownerId).catch(() => undefined)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
const context: AutomodContext = {
|
const context: AutomodContext = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
|
@ -44,6 +36,7 @@ export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginTyp
|
||||||
deleted: thread,
|
deleted: thread,
|
||||||
},
|
},
|
||||||
user,
|
user,
|
||||||
|
channel: thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
pluginData.state.queue.add(() => {
|
pluginData.state.queue.add(() => {
|
||||||
|
|
|
@ -15,9 +15,11 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
|
||||||
const member = context.member || (userId && pluginData.guild.members.cache.get(userId as Snowflake)) || null;
|
const member = context.member || (userId && pluginData.guild.members.cache.get(userId as Snowflake)) || null;
|
||||||
|
|
||||||
const channelIdOrThreadId = context.message?.channel_id;
|
const channelIdOrThreadId = context.message?.channel_id;
|
||||||
const channelOrThread = channelIdOrThreadId
|
const channelOrThread =
|
||||||
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel)
|
context.channel ??
|
||||||
: null;
|
(channelIdOrThreadId
|
||||||
|
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel)
|
||||||
|
: null);
|
||||||
const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId;
|
const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId;
|
||||||
const threadId = channelOrThread?.isThread() ? channelOrThread.id : null;
|
const threadId = channelOrThread?.isThread() ? channelOrThread.id : null;
|
||||||
const channel = channelOrThread?.isThread() ? channelOrThread.parent : channelOrThread;
|
const channel = channelOrThread?.isThread() ? channelOrThread.parent : channelOrThread;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Snowflake } from "discord-api-types";
|
import { Snowflake } from "discord-api-types";
|
||||||
import { ThreadChannel, User, Util } from "discord.js";
|
import { User, Util } from "discord.js";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { tNullable } from "../../../utils";
|
|
||||||
import { automodTrigger } from "../helpers";
|
import { automodTrigger } from "../helpers";
|
||||||
|
|
||||||
interface ThreadCreateResult {
|
interface ThreadCreateResult {
|
||||||
|
@ -13,24 +12,16 @@ interface ThreadCreateResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ThreadCreateTrigger = automodTrigger<ThreadCreateResult>()({
|
export const ThreadCreateTrigger = automodTrigger<ThreadCreateResult>()({
|
||||||
configType: t.type({
|
configType: t.type({}),
|
||||||
parent: tNullable(t.union([t.string, t.array(t.string)])),
|
|
||||||
}),
|
|
||||||
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
|
|
||||||
async match({ context, triggerConfig }) {
|
async match({ context }) {
|
||||||
if (!context.threadChange?.created) {
|
if (!context.threadChange?.created) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const thread = context.threadChange.created;
|
const thread = context.threadChange.created;
|
||||||
|
|
||||||
if (triggerConfig.parent) {
|
|
||||||
const parentIds = Array.isArray(triggerConfig.parent) ? triggerConfig.parent : [triggerConfig.parent];
|
|
||||||
if (thread.parentId && !parentIds.includes(thread.parentId)) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extra: {
|
extra: {
|
||||||
matchedThreadId: thread.id,
|
matchedThreadId: thread.id,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { Snowflake } from "discord-api-types";
|
import { Snowflake } from "discord-api-types";
|
||||||
import { User, Util } from "discord.js";
|
import { User, Util } from "discord.js";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { tNullable } from "../../../utils";
|
|
||||||
import { automodTrigger } from "../helpers";
|
import { automodTrigger } from "../helpers";
|
||||||
|
|
||||||
interface ThreadDeleteResult {
|
interface ThreadDeleteResult {
|
||||||
|
@ -13,24 +12,16 @@ interface ThreadDeleteResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
|
export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
|
||||||
configType: t.type({
|
configType: t.type({}),
|
||||||
parent: tNullable(t.union([t.string, t.array(t.string)])),
|
|
||||||
}),
|
|
||||||
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
|
|
||||||
async match({ context, triggerConfig }) {
|
async match({ context }) {
|
||||||
if (!context.threadChange?.deleted) {
|
if (!context.threadChange?.deleted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const thread = context.threadChange.deleted;
|
const thread = context.threadChange.deleted;
|
||||||
|
|
||||||
if (triggerConfig.parent) {
|
|
||||||
const parentIds = Array.isArray(triggerConfig.parent) ? triggerConfig.parent : [triggerConfig.parent];
|
|
||||||
if (thread.parentId && !parentIds.includes(thread.parentId)) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
extra: {
|
extra: {
|
||||||
matchedThreadId: thread.id,
|
matchedThreadId: thread.id,
|
||||||
|
@ -53,7 +44,8 @@ export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
|
||||||
threadOwner.tag,
|
threadOwner.tag,
|
||||||
)}** (\`${threadOwner.id}\`) in the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
|
)}** (\`${threadOwner.id}\`) in the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
|
||||||
}
|
}
|
||||||
return `Thread **#${threadName ??
|
return `Thread **#${
|
||||||
"Unknown"}** (\`${threadId}\`) from the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
|
threadName ?? "Unknown"
|
||||||
|
}** (\`${threadId}\`) from the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { GuildMember, PartialGuildMember, ThreadChannel, User } from "discord.js";
|
import { GuildMember, PartialGuildMember, TextChannel, ThreadChannel, User } from "discord.js";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { BasePluginType, CooldownManager } from "knub";
|
import { BasePluginType, CooldownManager } from "knub";
|
||||||
import { SavedMessage } from "../../data/entities/SavedMessage";
|
import { SavedMessage } from "../../data/entities/SavedMessage";
|
||||||
|
@ -135,6 +135,7 @@ export interface AutomodContext {
|
||||||
created?: ThreadChannel;
|
created?: ThreadChannel;
|
||||||
deleted?: ThreadChannel;
|
deleted?: ThreadChannel;
|
||||||
};
|
};
|
||||||
|
channel?: TextChannel | ThreadChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RecentAction {
|
export interface RecentAction {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue