Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve thread types after my djs pr is merged #602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/auto/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
ComponentType,
MessageType,
TextInputStyle,
type AnyThreadChannel,
type ButtonInteraction,
type InteractionResponse,
type Message,
type MessageContextMenuCommandInteraction,
type Snowflake,
type ThreadChannel,
} from "discord.js";
import mongoose from "mongoose";
import { client } from "strife.js";
Expand Down Expand Up @@ -115,7 +115,7 @@ export async function learn(message: Message): Promise<void> {
}

const thread = await getThread();
async function getThread(): Promise<ThreadChannel | undefined> {
async function getThread(): Promise<AnyThreadChannel | undefined> {
if (!config.channels.bots) return;

const intitialThread = getInitialChannelThreads(config.channels.bots).find(
Expand Down
5 changes: 3 additions & 2 deletions modules/logging/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
type Sticker,
type TextBasedChannel,
type TextChannel,
type ThreadChannel,
type User,
type Webhook,
} from "discord.js";
Expand Down Expand Up @@ -180,7 +179,9 @@ export default async function log(
});
}

export async function getLoggingThread(group: LogSeverity): Promise<TextChannel | ThreadChannel> {
export async function getLoggingThread(
group: LogSeverity,
): Promise<AnyThreadChannel | TextChannel> {
if (!config.channels.modlogs) throw new ReferenceError("Cannot find logs channel");
if (group === LogSeverity.Alert) return config.channels.modlogs;

Expand Down
4 changes: 2 additions & 2 deletions modules/tickets/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
channelMention,
type APIEmbedField,
type AnySelectMenuInteraction,
type AnyThreadChannel,
type ButtonInteraction,
type InteractionResponse,
type RepliableInteraction,
type ThreadChannel,
} from "discord.js";
import config from "../../common/config.js";
import constants from "../../common/constants.js";
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function showTicketModal(
export default async function contactMods(
interaction: RepliableInteraction,
options: Category | GuildMember,
): Promise<ThreadChannel> {
): Promise<AnyThreadChannel> {
const category = options instanceof GuildMember ? MOD_CATEGORY : options;

const member =
Expand Down
17 changes: 6 additions & 11 deletions modules/tickets/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ import {
ChannelType,
ComponentType,
TextInputStyle,
type PrivateThreadChannel,
type Snowflake,
type TextInputComponentData,
type ThreadChannel,
} from "discord.js";
import config, { getInitialChannelThreads } from "../../common/config.js";

export const TICKETS_BY_MEMBER = Object.fromEntries<
PrivateThreadChannel | ThreadChannel | undefined
>(
export const TICKETS_BY_MEMBER = Object.fromEntries(
config.channels.tickets
? getInitialChannelThreads(config.channels.tickets)
.map(
(thread) =>
thread.type === ChannelType.PrivateThread &&
([getIdFromName(thread.name) ?? "", thread] as const),
)
.filter(Boolean)
.filter((thread) => thread.type === ChannelType.PrivateThread)
.map((thread) => {
const id = getIdFromName(thread.name);
return [id ?? "", id ? thread : undefined] as const;
})
: [],
);

Expand Down
9 changes: 2 additions & 7 deletions util/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
type PartialDMChannel,
type Snowflake,
type TextBasedChannel,
type ThreadChannel,
type User,
} from "discord.js";
import { client } from "strife.js";
Expand Down Expand Up @@ -183,15 +182,11 @@ export function getMessageJSON(message: Message): {
*
* @returns The messages.
*/
export async function getAllMessages(
channel: GuildTextBasedChannel | ThreadChannel,
): Promise<Message<true>[]>;
export async function getAllMessages(channel: GuildTextBasedChannel): Promise<Message<true>[]>;
export async function getAllMessages(
channel: DMChannel | PartialDMChannel,
): Promise<Message<false>[]>;
export async function getAllMessages(
channel: TextBasedChannel | ThreadChannel,
): Promise<Message[]> {
export async function getAllMessages(channel: TextBasedChannel): Promise<Message[]> {
const messages = [];

let lastId: Snowflake | undefined;
Expand Down