3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-16 14:11:50 +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 { import {
ChannelType,
GuildMember, GuildMember,
GuildTextBasedChannel, GuildTextBasedChannel,
Message, Message,
@ -197,7 +198,7 @@ export function getPluginConfigPreprocessor(
export async function sendSuccessMessage( export async function sendSuccessMessage(
pluginData: AnyPluginData<any>, pluginData: AnyPluginData<any>,
channel: TextChannel, channel: GuildTextBasedChannel,
body: string, body: string,
allowedMentions?: MessageMentionOptions, allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> { ): Promise<Message | undefined> {
@ -218,7 +219,7 @@ export async function sendSuccessMessage(
export async function sendErrorMessage( export async function sendErrorMessage(
pluginData: AnyPluginData<any>, pluginData: AnyPluginData<any>,
channel: GuildTextBasedChannel, channel: TextBasedChannel,
body: string, body: string,
allowedMentions?: MessageMentionOptions, allowedMentions?: MessageMentionOptions,
): Promise<Message | undefined> { ): Promise<Message | undefined> {

View file

@ -17,7 +17,7 @@ export async function deleteNextItem(pluginData: GuildPluginData<AutoDeletePlugi
scheduleNextDeletion(pluginData); 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) { if (!channel) {
// Channel was deleted, ignore // Channel was deleted, ignore
return; 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 * as t from "io-ts";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { noop } from "../../../utils"; import { noop } from "../../../utils";
@ -32,7 +32,7 @@ export const CleanAction = automodAction({
pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id); 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); 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 * as t from "io-ts";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
@ -66,7 +74,7 @@ export const ReplyAction = automodAction({
: ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions); : ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions);
if (formatted) { 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 // Check for basic Send Messages and View Channel permissions
if ( 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 * as t from "io-ts";
import { LogType } from "../../../data/LogType"; import { LogType } from "../../../data/LogType";
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; 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); const channel = pluginData.guild.channels.cache.get(channelId as Snowflake);
// Only text channels and text channels within categories support slowmodes // 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; continue;
} }
const channelsToSlowmode: TextChannel[] = []; const channelsToSlowmode: GuildTextBasedChannel[] = [];
if (channel.type === ChannelType.GuildCategory) { if (channel.type === ChannelType.GuildCategory) {
// Find all text channels within the category // Find all text channels within the category
for (const ch of pluginData.guild.channels.cache.values()) { for (const ch of pluginData.guild.channels.cache.values()) {
if (ch.parentId === channel.id && ch.type === ChannelType.GuildText) { if (ch.parentId === channel.id && ch.type === ChannelType.GuildText) {
channelsToSlowmode.push(ch as TextChannel); channelsToSlowmode.push(ch);
} }
} }
} else { } else {
channelsToSlowmode.push(channel as TextChannel); channelsToSlowmode.push(channel);
} }
const slowmodeSeconds = Math.ceil(slowmodeMs / 1000); const slowmodeSeconds = Math.ceil(slowmodeMs / 1000);

View file

@ -1,5 +1,5 @@
import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types/v9"; 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 * as t from "io-ts";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils"; import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from "../../../utils";
@ -52,7 +52,7 @@ export const StartThreadAction = automodAction({
: ThreadAutoArchiveDuration.OneHour; : ThreadAutoArchiveDuration.OneHour;
for (const threadContext of threads) { 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) => const renderThreadName = async (str: string) =>
renderTemplate( renderTemplate(
str, str,
@ -62,7 +62,7 @@ export const StartThreadAction = automodAction({
}), }),
); );
const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread"); const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread");
const thread = await channel.threads const thread = await channel!.threads
.create({ .create({
name: threadName, name: threadName,
autoArchiveDuration: autoArchive, 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 { GuildPluginData } from "knub";
import { messageSummary, verboseChannelMention } from "../../../utils"; import { messageSummary, verboseChannelMention } from "../../../utils";
import { AutomodContext, AutomodPluginType } from "../types"; import { AutomodContext, AutomodPluginType } from "../types";
@ -11,13 +11,13 @@ export function getTextMatchPartialSummary(
) { ) {
if (type === "message") { if (type === "message") {
const message = context.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}\``; const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message in ${channelMention}:\n${messageSummary(message)}`; return `message in ${channelMention}:\n${messageSummary(message)}`;
} else if (type === "embed") { } else if (type === "embed") {
const message = context.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}\``; const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``;
return `message embed in ${channelMention}:\n${messageSummary(message)}`; return `message embed in ${channelMention}:\n${messageSummary(message)}`;
@ -29,6 +29,6 @@ export function getTextMatchPartialSummary(
const visibleName = context.member?.nickname || context.user!.username; const visibleName = context.member?.nickname || context.user!.username;
return `visible name: ${visibleName}`; return `visible name: ${visibleName}`;
} else if (type === "customstatus") { } 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 { GuildPluginData } from "knub";
import { availableActions } from "../actions/availableActions"; import { availableActions } from "../actions/availableActions";
import { CleanAction } from "../actions/clean"; import { CleanAction } from "../actions/clean";
@ -18,7 +18,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
const channelOrThread = const channelOrThread =
context.channel ?? context.channel ??
(channelIdOrThreadId (channelIdOrThreadId
? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel) ? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as GuildTextBasedChannel)
: null); : 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;

View file

@ -22,7 +22,7 @@ export const AnyMessageTrigger = automodTrigger<AnyMessageResultType>()({
}, },
renderMatchInformation({ pluginData, contexts, matchResult }) { 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 ${ return `Matched message (\`${contexts[0].message!.id}\`) in ${
channel ? verboseChannelMention(channel) : "Unknown Channel" channel ? verboseChannelMention(channel) : "Unknown Channel"
}`; }`;

View file

@ -66,7 +66,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger<MatchResultType>()({
}, },
renderMatchInformation({ pluginData, contexts, matchResult }) { 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); const prettyChannel = verboseChannelMention(channel);
return ( 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 * 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";
@ -139,7 +139,7 @@ export interface AutomodContext {
locked?: ThreadChannel; locked?: ThreadChannel;
unlocked?: ThreadChannel; unlocked?: ThreadChannel;
}; };
channel?: TextChannel | ThreadChannel; channel?: GuildTextBasedChannel;
} }
export interface RecentAction { export interface RecentAction {

View file

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

View file

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

View file

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