Release/1.0.0 #14

Merged
AstroGD merged 21 commits from release/1.0.0 into main 2022-11-29 03:21:57 +01:00
Showing only changes of commit a8cd924e18 - Show all commits

View File

@ -1,8 +1,8 @@
import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js"; import { SlashCommandBuilder, PermissionFlagsBits, ChannelType, ChatInputCommandInteraction, NewsChannel, TextBasedChannel, CategoryChannel, StageChannel, TextChannel, PrivateThreadChannel, PublicThreadChannel, VoiceChannel, APIInteractionDataResolvedChannel, ForumChannel } from "discord.js";
import getDefaultEmbed, { getSuccessEmbed } from "../tools/defaultEmbeds"; import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
import { database, GuildSetting } from "../data"; import { database, GuildSetting } from "../data";
import { getGuildSetting } from "../tools/data"; import { getGuildSetting } from "../tools/data";
import { getGuildChannel } from "../tools/discord"; import { getGuildChannel, getChannelPermission } from "../tools/discord";
import { Emoji } from "../tools/design"; import { Emoji } from "../tools/design";
const builder = new SlashCommandBuilder(); const builder = new SlashCommandBuilder();
@ -20,7 +20,7 @@ builder.addChannelOption((option) => {
async function resetNotificationChannel(guildSetting: GuildSetting, interaction: ChatInputCommandInteraction): Promise<void> { async function resetNotificationChannel(guildSetting: GuildSetting, interaction: ChatInputCommandInteraction): Promise<void> {
const logChannel = guildSetting.notificationChannelID ? await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID) : null; const logChannel = guildSetting.notificationChannelID ? await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID) : null;
guildSetting.notificationChannelID = null; guildSetting.notificationChannelID = null;
await database.getRepository(GuildSetting).save(guildSetting); await database.getRepository(GuildSetting).save(guildSetting);
@ -31,7 +31,7 @@ async function resetNotificationChannel(guildSetting: GuildSetting, interaction:
name: "This action was performed by", name: "This action was performed by",
value: `${interaction.user.tag} (${interaction.user.id})` value: `${interaction.user.tag} (${interaction.user.id})`
}); });
if (logChannel && logChannel.isTextBased()) { if (logChannel && logChannel.isTextBased()) {
logChannel.send({ logChannel.send({
embeds: [logEmbed] embeds: [logEmbed]
@ -55,6 +55,20 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
if (!optionVal) return await resetNotificationChannel(guildSetting, interaction); if (!optionVal) return await resetNotificationChannel(guildSetting, interaction);
const channel = getTextBasedChannel(optionVal); const channel = getTextBasedChannel(optionVal);
if (channel.isDMBased()) return;
const permissions = await getChannelPermission(channel);
if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) {
const embed = getFailedEmbed();
embed.setDescription(`Bot doesn't have permission to view and/or write in channel <#${channel.id}>`);
interaction.reply({
embeds: [ embed ],
ephemeral: true
}).catch();
return;
}
if (guildSetting.notificationChannelID) { if (guildSetting.notificationChannelID) {
const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID); const oldLogChannel = await getGuildChannel(guildSetting.id, guildSetting.notificationChannelID);
const embed = getDefaultEmbed(); const embed = getDefaultEmbed();
@ -84,14 +98,14 @@ const execute = async (interaction: ChatInputCommandInteraction) => {
}); });
channel.send({ channel.send({
embeds: [ embed ] embeds: [embed]
}).catch(); }).catch();
const reply = getSuccessEmbed(); const reply = getSuccessEmbed();
reply.setDescription(`Log channel was set to <#${channel.id}>`); reply.setDescription(`Log channel was set to <#${channel.id}>`);
interaction.reply({ interaction.reply({
embeds: [ reply ], embeds: [reply],
ephemeral: true ephemeral: true
}).catch(); }).catch();