3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-11 04:57:19 +00:00

remove config in favour of overrides

This commit is contained in:
almeidx 2021-10-26 23:48:18 +01:00
parent 11a4f30996
commit a9351d07cd
No known key found for this signature in database
GPG key ID: 01C5E03866747F46
6 changed files with 23 additions and 61 deletions

View file

@ -25,23 +25,6 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
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 {
const data: ISavedMessageData = {
author: {

View file

@ -5,28 +5,18 @@ import { AutomodContext, AutomodPluginType } from "../types";
export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginType>()({
event: "threadCreate",
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 = {
timestamp: Date.now(),
threadChange: {
created: thread,
},
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(() => {
runAutomod(pluginData, context);
});
@ -36,7 +26,9 @@ export const RunAutomodOnThreadCreate = typedGuildEventListener<AutomodPluginTyp
export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginType>()({
event: "threadDelete",
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 = {
timestamp: Date.now(),
@ -44,6 +36,7 @@ export const RunAutomodOnThreadDelete = typedGuildEventListener<AutomodPluginTyp
deleted: thread,
},
user,
channel: thread,
};
pluginData.state.queue.add(() => {

View file

@ -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 channelIdOrThreadId = context.message?.channel_id;
const channelOrThread = channelIdOrThreadId
const channelOrThread =
context.channel ??
(channelIdOrThreadId
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel)
: null;
: null);
const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId;
const threadId = channelOrThread?.isThread() ? channelOrThread.id : null;
const channel = channelOrThread?.isThread() ? channelOrThread.parent : channelOrThread;

View file

@ -1,7 +1,6 @@
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 { tNullable } from "../../../utils";
import { automodTrigger } from "../helpers";
interface ThreadCreateResult {
@ -13,24 +12,16 @@ interface ThreadCreateResult {
}
export const ThreadCreateTrigger = automodTrigger<ThreadCreateResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
configType: t.type({}),
defaultConfig: {},
async match({ context, triggerConfig }) {
async match({ context }) {
if (!context.threadChange?.created) {
return;
}
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 {
extra: {
matchedThreadId: thread.id,

View file

@ -1,7 +1,6 @@
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 ThreadDeleteResult {
@ -13,24 +12,16 @@ interface ThreadDeleteResult {
}
export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
configType: t.type({
parent: tNullable(t.union([t.string, t.array(t.string)])),
}),
configType: t.type({}),
defaultConfig: {},
async match({ context, triggerConfig }) {
async match({ context }) {
if (!context.threadChange?.deleted) {
return;
}
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 {
extra: {
matchedThreadId: thread.id,
@ -53,7 +44,8 @@ export const ThreadDeleteTrigger = automodTrigger<ThreadDeleteResult>()({
threadOwner.tag,
)}** (\`${threadOwner.id}\`) in the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
}
return `Thread **#${threadName ??
"Unknown"}** (\`${threadId}\`) from the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
return `Thread **#${
threadName ?? "Unknown"
}** (\`${threadId}\`) from the **#${parentName}** (\`${parentId}\`) channel has been deleted`;
},
});

View file

@ -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 { BasePluginType, CooldownManager } from "knub";
import { SavedMessage } from "../../data/entities/SavedMessage";
@ -135,6 +135,7 @@ export interface AutomodContext {
created?: ThreadChannel;
deleted?: ThreadChannel;
};
channel?: TextChannel | ThreadChannel;
}
export interface RecentAction {