Skip to content

Commit

Permalink
fix(types): resolve type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gx1285 committed Sep 8, 2024
1 parent f1fbbd3 commit fd193f5
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 100 deletions.
12 changes: 3 additions & 9 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |

## 脆弱性の報告
Expand Down
3 changes: 1 addition & 2 deletions src/events/messageDelete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
57 changes: 30 additions & 27 deletions src/events/messageUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<t:${Math.floor(Date.now() / 1000) + 3600}:F> にお知らせします。`)
.setColor(Colors.Blue),
],
});
if (newMessage.channel.type === ChannelType.GuildText)
newMessage.channel.send({
embeds: [
new EmbedBuilder()
.setTitle('UPしました!')
.setDescription(`<t:${Math.floor(Date.now() / 1000) + 3600}:F> にお知らせします。`)
.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('</dissoku up:828002256690610256> でupできます。')
.setColor(Colors.Blue),
],
allowedMentions: { parse: ['roles'] },
});
if (newMessage.channel.type === ChannelType.GuildText)
newMessage.channel.send({
content: `<@&${role}>`,
embeds: [
new EmbedBuilder()
.setTitle('UPできます!')
.setDescription('</dissoku up:828002256690610256> でupできます。')
.setColor(Colors.Blue),
],
allowedMentions: { parse: ['roles'] },
});
} else {
newMessage.channel.send({
embeds: [
new EmbedBuilder()
.setTitle('UPできます!')
.setDescription('</dissoku up:828002256690610256> でupできます。')
.setColor(Colors.Blue),
],
});
if (newMessage.channel.type === ChannelType.GuildText)
newMessage.channel.send({
embeds: [
new EmbedBuilder()
.setTitle('UPできます!')
.setDescription('</dissoku up:828002256690610256> でupできます。')
.setColor(Colors.Blue),
],
});
}
}, 3_600_000);
}
Expand Down Expand Up @@ -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));
Expand Down
39 changes: 21 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { exit } from 'node:process';
import { inspect } from 'node:util';
import {
ActivityType,
ChannelType,
Client,
Collection,
Colors,
Expand Down Expand Up @@ -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) => {
Expand All @@ -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()),
],
});
}
});
});
22 changes: 15 additions & 7 deletions src/interactions/appCommand.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
71 changes: 38 additions & 33 deletions src/messages/serverUp.ts
Original file line number Diff line number Diff line change
@@ -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(`<t:${Math.floor(Date.now() / 1000) + 7200}:F> にお知らせします。`)
.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:947088344167366698> でbumpできます。')
.setTitle('Bumpしました!')
.setDescription(`<t:${Math.floor(Date.now() / 1000) + 7200}:F> にお知らせします。`)
.setColor(Colors.Blue),
],
allowedMentions: { parse: ['roles'] },
});
} else {
message.channel.send({
embeds: [
new EmbedBuilder()
.setTitle('Bumpできます!')
.setDescription('</bump:947088344167366698> で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:947088344167366698> でbumpできます。')
.setColor(Colors.Blue),
],
allowedMentions: { parse: ['roles'] },
});
} else {
if (message.channel.type === ChannelType.GuildText)
message.channel.send({
embeds: [
new EmbedBuilder()
.setTitle('Bumpできます!')
.setDescription('</bump:947088344167366698> でbumpできます。')
.setColor(Colors.Blue),
],
});
}
}, 7_200_000);
}
}
}
5 changes: 2 additions & 3 deletions src/messages/superGlobalChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/messages/superGlobalChatDataGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit fd193f5

Please sign in to comment.