3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

more typings

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
metal 2023-03-11 14:55:31 +00:00 committed by GitHub
parent 010451c7e7
commit b9f2aee8b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 44 additions and 30 deletions

View file

@ -3,6 +3,7 @@
*/
import {
ChannelType,
GuildMember,
GuildTextBasedChannel,
Message,
@ -197,7 +198,7 @@ export function getPluginConfigPreprocessor(
export async function sendSuccessMessage(
pluginData: AnyPluginData<any>,
channel: TextChannel,
channel: GuildTextBasedChannel,
body: string,
allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> {
@ -218,7 +219,7 @@ export async function sendSuccessMessage(
export async function sendErrorMessage(
pluginData: AnyPluginData<any>,
channel: GuildTextBasedChannel,
channel: TextBasedChannel,
body: string,
allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> {

View file

@ -17,7 +17,7 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
scheduleNextDeletion(pluginData);
const channel = pluginData.guild.channels.cache.get(itemToDelete.message.channel_id as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(itemToDelete.message.channel_id as Snowflake);
if (!channel) {
// Channel was deleted, ignore
return;

View file

@ -1,4 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import { GuildTextBasedChannel, Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { noop } from "../../../utils";
@ -32,7 +32,7 @@ export const CleanAction = automodAction({
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id);
}
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as GuildTextBasedChannel;
await channel.bulkDelete(messageIds as Snowflake[]).catch(noop);
}
},

View file

@ -1,4 +1,12 @@
import { MessageOptions, PermissionsBitField, Snowflake, TextChannel, ThreadChannel, User } from "discord.js";
import {
GuildTextBasedChannel,
MessageOptions,
PermissionsBitField,
Snowflake,
TextChannel,
ThreadChannel,
User,
} from "discord.js";
import * as t from "io-ts";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
@ -66,7 +74,7 @@ export const ReplyAction = automodAction({
: ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
if (formatted) {
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as GuildTextBasedChannel;
// Check for basic Send Messages and View Channel permissions
if (

View file

@ -1,4 +1,4 @@
import { ChannelType, Snowflake, TextChannel } from "discord.js";
import { ChannelType, GuildTextBasedChannel, Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { LogType } from "../../../data/LogType";
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
@ -22,20 +22,20 @@ export const SetSlowmodeAction = automodAction({
const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes
if (!channel || !(channel.type === ChannelType.GuildText || ChannelType.GuildCategory)) {
if (!channel || (!channel.isTextBased() && channel.type !== ChannelType.GuildCategory)) {
continue;
}
const channelsToSlowmode: TextChannel[] = [];
const channelsToSlowmode: GuildTextBasedChannel[] = [];
if (channel.type === ChannelType.GuildCategory) {
// Find all text channels within the category
for (const ch of pluginData.guild.channels.cache.values()) {
if (ch.parentId === channel.id && ch.type === ChannelType.GuildText) {
channelsToSlowmode.push(ch as TextChannel);
channelsToSlowmode.push(ch);
}
}
} else {
channelsToSlowmode.push(channel as TextChannel);
channelsToSlowmode.push(channel);
}
const slowmodeSeconds = Math.ceil(slowmodeMs / 1000);

View file

@ -1,5 +1,5 @@
import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types/v9";
import { ChannelType, TextChannel } from "discord.js";
import { BaseGuildTextChannel, ChannelType, GuildTextBasedChannel, TextChannel } from "discord.js";
import * as t from "io-ts";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils";
@ -52,7 +52,7 @@ export const StartThreadAction = automodAction({
: ThreadAutoArchiveDuration.OneHour;
for (const threadContext of threads) {
const channel = pluginData.guild.channels.cache.get(threadContext.message!.channel_id) as TextChannel;
const channel = pluginData.guild.channels.cache.get(threadContext.message!.channel_id) as BaseGuildTextChannel;
const renderThreadName = async (str: string) =>
renderTemplate(
str,
@ -62,7 +62,7 @@ export const StartThreadAction = automodAction({
}),
);
const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread");
const thread = await channel.threads
const thread = await channel!.threads
.create({
name: threadName,
autoArchiveDuration: autoArchive,

View file

@ -1,4 +1,4 @@
import { Snowflake, TextChannel } from "discord.js";
import { ActivityType, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { messageSummary, verboseChannelMention } from "../../../utils";
import { AutomodContext, AutomodPluginType } from "../types";
@ -11,13 +11,13 @@ export function getTextMatchPartialSummary(
) {
if (type === "message") {
const message = context.message!;
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "embed") {
const message = context.message!;
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake);
const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message embed in ${channelMention}:\n${messageSummary(message)}`;
@ -29,6 +29,6 @@ export function getTextMatchPartialSummary(
const visibleName = context.member?.nickname || context.user!.username;
return `visible name: ${visibleName}`;
} else if (type === "customstatus") {
return `custom status: ${context.member!.presence?.activities.find((a) => a.type === "CUSTOM")?.name}`;
return `custom status: ${context.member!.presence?.activities.find((a) => a.type === ActivityType.Custom)?.name}`;
}
}

View file

@ -1,4 +1,4 @@
import { Snowflake, TextChannel, ThreadChannel } from "discord.js";
import { GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { availableActions } from "../actions/availableActions";
import { CleanAction } from "../actions/clean";
@ -18,7 +18,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
const channelOrThread =
context.channel ??
(channelIdOrThreadId
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel)
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as GuildTextBasedChannel)
: null);
const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId;
const threadId = channelOrThread?.isThread() ? channelOrThread.id : null;

View file

@ -22,7 +22,7 @@ export const AnyMessageTrigger = automodTrigger<AnyMessageResultType>()({
},
renderMatchInformation({ pluginData, contexts, matchResult }) {
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake);
return `Matched message (\`${contexts[0].message!.id}\`) in ${
channel ? verboseChannelMention(channel) : "Unknown Channel"
}`;

View file

@ -66,7 +66,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
},
renderMatchInformation({ pluginData, contexts, matchResult }) {
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel;
const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake);
const prettyChannel = verboseChannelMention(channel);
return (

View file

@ -1,4 +1,4 @@
import { GuildMember, PartialGuildMember, TextChannel, ThreadChannel, User } from "discord.js";
import { GuildMember, GuildTextBasedChannel, PartialGuildMember, TextChannel, ThreadChannel, User } from "discord.js";
import * as t from "io-ts";
import { BasePluginType, CooldownManager } from "knub";
import { SavedMessage } from "../../data/entities/SavedMessage";
@ -139,7 +139,7 @@ export interface AutomodContext {
locked?: ThreadChannel;
unlocked?: ThreadChannel;
};
channel?: TextChannel | ThreadChannel;
channel?: GuildTextBasedChannel;
}
export interface RecentAction {

View file

@ -19,7 +19,7 @@ export const AddDashboardUserCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
if (!guild) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin");
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
return;
}

View file

@ -952,7 +952,7 @@ export function chunkMessageLines(str: string, maxChunkLength = 1990): string[]
}
export async function createChunkedMessage(
channel: TextChannel | ThreadChannel | User,
channel: GuildTextBasedChannel | User,
messageText: string,
allowedMentions?: MessageMentionOptions,
) {
@ -1402,7 +1402,11 @@ export async function resolveStickerId(bot: Client, id: Snowflake): Promise<Stic
return fetchedSticker;
}
export async function confirm(channel: TextChannel, userId: string, content: MessageOptions): Promise<boolean> {
export async function confirm(
channel: GuildTextBasedChannel,
userId: string,
content: MessageOptions,
): Promise<boolean> {
return waitForButtonConfirm(channel, content, { restrictToId: userId });
}
@ -1441,7 +1445,7 @@ export function verboseUserName(user: User | UnknownUser): string {
return `**${user.tag}** (\`${user.id}\`)`;
}
export function verboseChannelMention(channel: GuildChannel | ThreadChannel): string {
export function verboseChannelMention(channel: GuildTextBasedChannel): string {
const plainTextName =
channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice
? channel.name

View file

@ -4,6 +4,7 @@ import {
ButtonBuilder,
ButtonComponent,
ButtonStyle,
GuildTextBasedChannel,
Message,
MessageActionRowComponentBuilder,
MessageComponentInteraction,
@ -16,7 +17,7 @@ import moment from "moment";
import uuidv4 from "uuid/v4";
export async function waitForButtonConfirm(
channel: TextChannel,
channel: GuildTextBasedChannel,
toPost: MessageCreateOptions,
options?: WaitForOptions,
): Promise<boolean> {