Better typeguard (#162)
All checks were successful
Lint and Format Check / lint-and-format (pull_request) Successful in 14s

This commit is contained in:
Mylloon 2024-09-17 11:03:13 +02:00
parent 755d4295ce
commit 570e94dd48
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 10 additions and 17 deletions

View file

@ -1,6 +1,6 @@
import { SlashCommandBuilder } from "@discordjs/builders"; import { SlashCommandBuilder } from "@discordjs/builders";
import { Player, useMainPlayer, useQueue } from "discord-player"; import { Player, useMainPlayer, useQueue } from "discord-player";
import { ChannelType, ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js";
import { getLocale, getLocalizations } from "../../utils/locales"; import { getLocale, getLocalizations } from "../../utils/locales";
import { getFilename } from "../../utils/misc"; import { getFilename } from "../../utils/misc";
@ -131,12 +131,12 @@ export default {
syncedLyrics?.onChange(async (lyrics) => { syncedLyrics?.onChange(async (lyrics) => {
const content = `[${data[0].trackName}]: ${lyrics}`; const content = `[${data[0].trackName}]: ${lyrics}`;
if (interaction.channel?.type === ChannelType.GroupDM) { if (interaction.channel?.isSendable()) {
await interaction.followUp({ await interaction.channel?.send({
content, content,
}); });
} else { } else {
await interaction.channel?.send({ await interaction.followUp({
content, content,
}); });
} }

View file

@ -1,11 +1,4 @@
import { import { Client, EmbedBuilder, GuildMember, Message, TextBasedChannel } from "discord.js";
ChannelType,
Client,
EmbedBuilder,
GuildMember,
Message,
TextBasedChannel,
} from "discord.js";
import { getLocale } from "../../utils/locales"; import { getLocale } from "../../utils/locales";
import { isImage, userWithNickname } from "../../utils/misc"; import { isImage, userWithNickname } from "../../utils/misc";
import { showDate } from "../../utils/time"; import { showDate } from "../../utils/time";
@ -172,7 +165,7 @@ export default async (message: Message, client: Client) => {
!message.content.replace(new RegExp(regex, "g"), "").trim() && !message.content.replace(new RegExp(regex, "g"), "").trim() &&
messages.length === urls.length && messages.length === urls.length &&
!message.mentions.repliedUser && !message.mentions.repliedUser &&
message.channel.type !== ChannelType.GroupDM message.channel.isSendable()
) { ) {
message.delete(); message.delete();
return message.channel.send({ embeds: [embed] }); return message.channel.send({ embeds: [embed] });

View file

@ -1,6 +1,6 @@
import { EmbedBuilder } from "@discordjs/builders"; import { EmbedBuilder } from "@discordjs/builders";
import { GuildQueue, Track } from "discord-player"; import { GuildQueue, Track } from "discord-player";
import { ChannelType, Client } from "discord.js"; import { Client } from "discord.js";
import { Metadata } from "../../utils/metadata"; import { Metadata } from "../../utils/metadata";
import { emojiPng } from "../../utils/misc"; import { emojiPng } from "../../utils/misc";
@ -20,7 +20,7 @@ export default (queue: GuildQueue<Metadata>, track: Track, client: Client) => {
iconURL: emojiPng("🎶"), iconURL: emojiPng("🎶"),
}); });
if (queue.metadata.channel?.type !== ChannelType.GroupDM) { if (queue.metadata.channel?.isSendable()) {
queue.metadata?.channel?.send({ embeds: [embed] }); queue.metadata?.channel?.send({ embeds: [embed] });
} }
}; };

View file

@ -1,4 +1,4 @@
import { ChannelType, Client, Colors, EmbedBuilder, User } from "discord.js"; import { Client, Colors, EmbedBuilder, User } from "discord.js";
import { getLocale } from "./locales"; import { getLocale } from "./locales";
import { cleanCodeBlock } from "./misc"; import { cleanCodeBlock } from "./misc";
import { showDate, strToSeconds, timeDeltaToString } from "./time"; import { showDate, strToSeconds, timeDeltaToString } from "./time";
@ -169,7 +169,7 @@ export const sendReminder = (client: Client, info: infoReminder, option: OptionR
} else { } else {
// Channel // Channel
client.channels.fetch(info.channelId ?? "").then((channel) => { client.channels.fetch(info.channelId ?? "").then((channel) => {
if (channel?.isTextBased() && channel.type !== ChannelType.GroupDM) { if (channel?.isSendable()) {
let content = `<@${info.userId}>`; let content = `<@${info.userId}>`;
embed.setFooter({ embed.setFooter({
text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`, text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`,