From fd193f5ba3db0d63f06fac2fd81cc2af594b7e3b Mon Sep 17 00:00:00 2001 From: gx1285 Date: Sun, 8 Sep 2024 17:29:17 +0900 Subject: [PATCH] fix(types): resolve type errors --- SECURITY.md | 12 ++--- src/events/messageDelete.ts | 3 +- src/events/messageUpdate.ts | 57 +++++++++++---------- src/index.ts | 39 +++++++------- src/interactions/appCommand.ts | 22 +++++--- src/messages/serverUp.ts | 71 ++++++++++++++------------ src/messages/superGlobalChat.ts | 5 +- src/messages/superGlobalChatDataGet.ts | 2 +- 8 files changed, 111 insertions(+), 100 deletions(-) diff --git a/SECURITY.md b/SECURITY.md index 528c4ca..8617d05 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,15 +5,9 @@ | Version | Supported | | ------- | ------------------ | | main | :white_check_mark: | -| 3.4.x | :white_check_mark: | -| 3.3.x | :x: | -| 3.2.x | :x: | -| 3.1.x | :x: | -| 3.0.x | :x: | -| 2.4.x | :x: | -| 2.3.x | :x: | -| 2.2.x | :x: | -| 2.1.x | :x: | +| 3.5.x | :white_check_mark: | +| 3.0-3.4 | :x: | +| 2.1-2.4 | :x: | | < 2.0.x | :x: | ## 脆弱性の報告 diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts index 882851a..6589542 100644 --- a/src/events/messageDelete.ts +++ b/src/events/messageDelete.ts @@ -46,8 +46,7 @@ async function sgc(message: Message) { webhook.deleteMessage(value.messageId); } const channel = message.client.channels.cache.get(message.client.botData.sgcJsonChannelIdv2); - if (channel && channel.isTextBased()) { - if (message.channel.type !== ChannelType.GuildText) return; + if (channel && channel.type === ChannelType.GuildText) { const data: MessageDeleteData = { type: 'delete', messageId: message.id }; channel.send(JSON.stringify(data)); } diff --git a/src/events/messageUpdate.ts b/src/events/messageUpdate.ts index 68ac005..9f50388 100644 --- a/src/events/messageUpdate.ts +++ b/src/events/messageUpdate.ts @@ -18,36 +18,39 @@ async function dissoku(newMessage: Message) { newMessage.embeds[0].fields[0] && newMessage.embeds[0].fields[0].value.includes('ActiveLevel') ) { - newMessage.channel.send({ - embeds: [ - new EmbedBuilder() - .setTitle('UPしました!') - .setDescription(` にお知らせします。`) - .setColor(Colors.Blue), - ], - }); + if (newMessage.channel.type === ChannelType.GuildText) + newMessage.channel.send({ + embeds: [ + new EmbedBuilder() + .setTitle('UPしました!') + .setDescription(` にお知らせします。`) + .setColor(Colors.Blue), + ], + }); setTimeout(async () => { const role = await newMessage.client.botData.guildUpNotice.dissoku.get(newMessage.guildId + '_role'); if (role) { - newMessage.channel.send({ - content: `<@&${role}>`, - embeds: [ - new EmbedBuilder() - .setTitle('UPできます!') - .setDescription(' でupできます。') - .setColor(Colors.Blue), - ], - allowedMentions: { parse: ['roles'] }, - }); + if (newMessage.channel.type === ChannelType.GuildText) + newMessage.channel.send({ + content: `<@&${role}>`, + embeds: [ + new EmbedBuilder() + .setTitle('UPできます!') + .setDescription(' でupできます。') + .setColor(Colors.Blue), + ], + allowedMentions: { parse: ['roles'] }, + }); } else { - newMessage.channel.send({ - embeds: [ - new EmbedBuilder() - .setTitle('UPできます!') - .setDescription(' でupできます。') - .setColor(Colors.Blue), - ], - }); + if (newMessage.channel.type === ChannelType.GuildText) + newMessage.channel.send({ + embeds: [ + new EmbedBuilder() + .setTitle('UPできます!') + .setDescription(' でupできます。') + .setColor(Colors.Blue), + ], + }); } }, 3_600_000); } @@ -144,7 +147,7 @@ async function superGlobalChat(newMessage: Message) { }); } const channel = newMessage.client.channels.cache.get(newMessage.client.botData.sgcJsonChannelIdv2); - if (channel && channel.isTextBased()) { + if (channel && channel.type === ChannelType.GuildText) { if (newMessage.channel.type !== ChannelType.GuildText) return; const data: MessageEditData = { type: 'edit', messageId: newMessage.id, content: newMessage.content }; channel.send(JSON.stringify(data)); diff --git a/src/index.ts b/src/index.ts index 39d6940..a304c8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,7 @@ import { exit } from 'node:process'; import { inspect } from 'node:util'; import { ActivityType, + ChannelType, Client, Collection, Colors, @@ -199,15 +200,16 @@ process.on('uncaughtException', (error) => { errors.set(errorId.toString(), inspect(error).slice(0, 1800)); client.channels.fetch(errorChannelId).then(async (channel) => { - if (!channel.isTextBased()) return; - channel.send({ - embeds: [ - new EmbedBuilder() - .setColor(Colors.Red) - .setTitle(':x: エラーが発生しました。') - .setDescription('Id: ' + errorId.toString()), - ], - }); + if (channel.type === ChannelType.GuildText) { + channel.send({ + embeds: [ + new EmbedBuilder() + .setColor(Colors.Red) + .setTitle(':x: エラーが発生しました。') + .setDescription('Id: ' + errorId.toString()), + ], + }); + } }); }); process.on('unhandledRejection', (error) => { @@ -216,14 +218,15 @@ process.on('unhandledRejection', (error) => { errors.set(errorId.toString(), inspect(error).slice(0, 1800)); client.channels.fetch(errorChannelId).then(async (channel) => { - if (!channel.isTextBased()) return; - channel.send({ - embeds: [ - new EmbedBuilder() - .setColor(Colors.Red) - .setTitle(':x: エラーが発生しました。') - .setDescription('Id: ' + errorId.toString()), - ], - }); + if (channel.type === ChannelType.GuildText) { + channel.send({ + embeds: [ + new EmbedBuilder() + .setColor(Colors.Red) + .setTitle(':x: エラーが発生しました。') + .setDescription('Id: ' + errorId.toString()), + ], + }); + } }); }); diff --git a/src/interactions/appCommand.ts b/src/interactions/appCommand.ts index 50dc096..8bc2140 100644 --- a/src/interactions/appCommand.ts +++ b/src/interactions/appCommand.ts @@ -1,4 +1,12 @@ -import { BaseInteraction, Collection, PermissionFlags, EmbedBuilder, SnowflakeUtil, Colors } from 'discord.js'; +import { + BaseInteraction, + Collection, + PermissionFlags, + EmbedBuilder, + SnowflakeUtil, + Colors, + ChannelType, +} from 'discord.js'; import { inspect } from 'node:util'; import { translatePermission } from '../utils/permission.js'; export default async function (interaction: BaseInteraction) { @@ -107,7 +115,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() @@ -128,7 +136,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() @@ -239,7 +247,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() @@ -260,7 +268,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() @@ -371,7 +379,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() @@ -392,7 +400,7 @@ export default async function (interaction: BaseInteraction) { true, ); const Errorchannel = channels.cache.get(botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() diff --git a/src/messages/serverUp.ts b/src/messages/serverUp.ts index 0ec9e7d..bae17d4 100644 --- a/src/messages/serverUp.ts +++ b/src/messages/serverUp.ts @@ -1,44 +1,49 @@ -import { EmbedBuilder, Message, Colors } from 'discord.js'; +import { EmbedBuilder, Message, Colors, ChannelType } from 'discord.js'; export default async function (message: Message) { if (!(await message.client.botData.guildUpNotice.disboard.get(message.guildId))) return; - if ( - message.author.id === '302050872383242240' && - message.embeds[0] && - message.embeds[0].image && - message.embeds[0].image.url.includes('disboard.org/images/bot-command-image-bump.png') - ) { - message.channel.send({ - embeds: [ - new EmbedBuilder() - .setTitle('Bumpしました!') - .setDescription(` にお知らせします。`) - .setColor(Colors.Blue), - ], - }); - setTimeout(async () => { - const role = await message.client.botData.guildUpNotice.disboard.get(message.guildId + '_role'); - if (role) { + if (message.channel.isTextBased() || message.inGuild()) { + if ( + message.author.id === '302050872383242240' && + message.embeds[0] && + message.embeds[0].image && + message.embeds[0].image.url.includes('disboard.org/images/bot-command-image-bump.png') + ) { + if (message.channel.type === ChannelType.GuildText) message.channel.send({ - content: `<@&${role}>`, embeds: [ new EmbedBuilder() - .setTitle('Bumpできます!') - .setDescription(' でbumpできます。') + .setTitle('Bumpしました!') + .setDescription(` にお知らせします。`) .setColor(Colors.Blue), ], - allowedMentions: { parse: ['roles'] }, }); - } else { - message.channel.send({ - embeds: [ - new EmbedBuilder() - .setTitle('Bumpできます!') - .setDescription(' でbumpできます。') - .setColor(Colors.Blue), - ], - }); - } - }, 7_200_000); + setTimeout(async () => { + const role = await message.client.botData.guildUpNotice.disboard.get(message.guildId + '_role'); + if (role) { + if (message.channel.type === ChannelType.GuildText) + message.channel.send({ + content: `<@&${role}>`, + embeds: [ + new EmbedBuilder() + .setTitle('Bumpできます!') + .setDescription(' でbumpできます。') + .setColor(Colors.Blue), + ], + allowedMentions: { parse: ['roles'] }, + }); + } else { + if (message.channel.type === ChannelType.GuildText) + message.channel.send({ + embeds: [ + new EmbedBuilder() + .setTitle('Bumpできます!') + .setDescription(' でbumpできます。') + .setColor(Colors.Blue), + ], + }); + } + }, 7_200_000); + } } } diff --git a/src/messages/superGlobalChat.ts b/src/messages/superGlobalChat.ts index 4a23c21..65a6f24 100644 --- a/src/messages/superGlobalChat.ts +++ b/src/messages/superGlobalChat.ts @@ -147,8 +147,7 @@ export default async function (message: Message) { }); message.react('✅'); const channel = message.client.channels.cache.get(message.client.botData.sgcJsonChannelId); - if (channel && channel.isTextBased()) { - if (message.channel.type !== ChannelType.GuildText) return; + if (channel && channel.type === ChannelType.GuildText) { channel.send(JSON.stringify(data)); } } catch (error) { @@ -158,7 +157,7 @@ export default async function (message: Message) { message.client.botData.errors.set(errorId.toString(), inspect(error).slice(0, 1800)); const Errorchannel = message.client.channels.cache.get(message.client.botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder() diff --git a/src/messages/superGlobalChatDataGet.ts b/src/messages/superGlobalChatDataGet.ts index bca91fe..f7a09fd 100644 --- a/src/messages/superGlobalChatDataGet.ts +++ b/src/messages/superGlobalChatDataGet.ts @@ -161,7 +161,7 @@ export default async function (message: Message) { message.client.botData.errors.set(errorId.toString(), inspect(error).slice(0, 1800)); const Errorchannel = message.client.channels.cache.get(message.client.botData.errorChannelId); - if (Errorchannel.isTextBased()) + if (Errorchannel.type === ChannelType.GuildText) Errorchannel.send({ embeds: [ new EmbedBuilder()