mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
fix(logs): fix inconsistent thread/channel/category exclusions; add excluded_threads log channel option
This commit is contained in:
parent
218c31231e
commit
d472fd4fa6
32 changed files with 132 additions and 51 deletions
6
backend/src/utils/isDmChannel.ts
Normal file
6
backend/src/utils/isDmChannel.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Channel, DMChannel } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
|
||||
export function isDmChannel(channel: Channel): channel is DMChannel {
|
||||
return channel.type === ChannelTypeStrings.DM || channel.type === ChannelTypeStrings.GROUP;
|
||||
}
|
5
backend/src/utils/isGuildChannel.ts
Normal file
5
backend/src/utils/isGuildChannel.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { Channel, GuildChannel } from "discord.js";
|
||||
|
||||
export function isGuildChannel(channel: Channel): channel is GuildChannel {
|
||||
return channel.type.startsWith("GUILD_");
|
||||
}
|
10
backend/src/utils/isThreadChannel.ts
Normal file
10
backend/src/utils/isThreadChannel.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { Channel, ThreadChannel } from "discord.js";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
|
||||
export function isThreadChannel(channel: Channel): channel is ThreadChannel {
|
||||
return (
|
||||
channel.type === ChannelTypeStrings.NEWS_THREAD ||
|
||||
channel.type === ChannelTypeStrings.PUBLIC_THREAD ||
|
||||
channel.type === ChannelTypeStrings.PRIVATE_THREAD
|
||||
);
|
||||
}
|
53
backend/src/utils/resolveChannelIds.ts
Normal file
53
backend/src/utils/resolveChannelIds.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
import { ChannelType } from "discord-api-types/v9";
|
||||
import { CategoryChannel, Channel } from "discord.js";
|
||||
import { ChannelTypes } from "discord.js/typings/enums";
|
||||
import { ChannelTypeStrings } from "src/types";
|
||||
import { isDmChannel } from "./isDmChannel";
|
||||
import { isGuildChannel } from "./isGuildChannel";
|
||||
import { isThreadChannel } from "./isThreadChannel";
|
||||
|
||||
type ResolvedChannelIds = {
|
||||
category: string | null;
|
||||
channel: string | null;
|
||||
thread: string | null;
|
||||
};
|
||||
|
||||
export function resolveChannelIds(channel: Channel): ResolvedChannelIds {
|
||||
if (isDmChannel(channel)) {
|
||||
return {
|
||||
category: null,
|
||||
channel: channel.id,
|
||||
thread: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (isThreadChannel(channel)) {
|
||||
return {
|
||||
category: channel.parent?.parentId || null,
|
||||
channel: channel.parentId,
|
||||
thread: channel.id,
|
||||
};
|
||||
}
|
||||
|
||||
if (channel instanceof CategoryChannel) {
|
||||
return {
|
||||
category: channel.id,
|
||||
channel: null,
|
||||
thread: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (isGuildChannel(channel)) {
|
||||
return {
|
||||
category: channel.parentId,
|
||||
channel: channel.id,
|
||||
thread: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
category: null,
|
||||
channel: channel.id,
|
||||
thread: null,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue