mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-11-02 11:07:40 +01:00
fix(arabot): check private channel already exists
This commit is contained in:
parent
2880283e9a
commit
8c395784d0
@ -18,13 +18,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Command, RegisterBehavior } from '@sapphire/framework';
|
import { Command, RegisterBehavior } from '@sapphire/framework';
|
||||||
import type { TextChannel } from 'discord.js';
|
import type { Guild, TextChannel } from 'discord.js';
|
||||||
import {
|
import {
|
||||||
CategoryChannel,
|
CategoryChannel,
|
||||||
ChannelType,
|
ChannelType,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
PermissionsBitField,
|
PermissionsBitField, Snowflake,
|
||||||
time,
|
time,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import IDs from '../../utils/ids';
|
import IDs from '../../utils/ids';
|
||||||
@ -116,6 +116,15 @@ class PrivateCommand extends Command {
|
|||||||
|
|
||||||
const [name, coordinator] = this.getCoordinator(modGuildMember);
|
const [name, coordinator] = this.getCoordinator(modGuildMember);
|
||||||
|
|
||||||
|
if (this.checkPrivate(guildMember.id, coordinator, guild)) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'A private channel already exists!',
|
||||||
|
ephemeral: true,
|
||||||
|
fetchReply: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const voiceChannel = await guild.channels.create({
|
const voiceChannel = await guild.channels.create({
|
||||||
name: 'Private Voice Channel',
|
name: 'Private Voice Channel',
|
||||||
type: ChannelType.GuildVoice,
|
type: ChannelType.GuildVoice,
|
||||||
@ -353,6 +362,25 @@ class PrivateCommand extends Command {
|
|||||||
}
|
}
|
||||||
return [name, id];
|
return [name, id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkPrivate(user: Snowflake, coordinator: string, guild: Guild) {
|
||||||
|
const category = guild.channels.cache.get(IDs.categories.private) as CategoryChannel | undefined;
|
||||||
|
|
||||||
|
if (category === undefined) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const textChannels = category.children.cache.filter((c) => c.type === ChannelType.GuildText);
|
||||||
|
let exists = false;
|
||||||
|
textChannels.forEach((c) => {
|
||||||
|
const textChannel = c as TextChannel;
|
||||||
|
// Checks if the channel topic has the user's snowflake
|
||||||
|
if (textChannel.topic?.includes(user) && textChannel.topic?.includes(coordinator)) {
|
||||||
|
exists = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return exists;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PrivateCommand;
|
export default PrivateCommand;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user