generated from Baipyrus/DiscordJS-Template
Compare commits
No commits in common. "fa6a9fa2e38edd2afdbb760fcc5cbff171aa9bf0" and "ab6ca9edeb0dff29184e957443bb7c84c17fafb7" have entirely different histories.
fa6a9fa2e3
...
ab6ca9edeb
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ChannelType,
|
ChannelType,
|
||||||
Events,
|
Events,
|
||||||
|
PermissionFlagsBits,
|
||||||
GuildMember,
|
GuildMember,
|
||||||
GuildChannelManager,
|
GuildChannelManager,
|
||||||
GuildChannel,
|
GuildChannel,
|
||||||
@ -8,6 +9,22 @@ import {
|
|||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { VoiceChannel } from '../../database.js';
|
import { VoiceChannel } from '../../database.js';
|
||||||
|
|
||||||
|
const vcPermissionOverwrites = [
|
||||||
|
PermissionFlagsBits.ReadMessageHistory,
|
||||||
|
PermissionFlagsBits.PrioritySpeaker,
|
||||||
|
PermissionFlagsBits.ManageMessages,
|
||||||
|
PermissionFlagsBits.ManageChannels,
|
||||||
|
PermissionFlagsBits.DeafenMembers,
|
||||||
|
PermissionFlagsBits.SendMessages,
|
||||||
|
PermissionFlagsBits.ViewChannel,
|
||||||
|
PermissionFlagsBits.MuteMembers,
|
||||||
|
PermissionFlagsBits.MoveMembers,
|
||||||
|
PermissionFlagsBits.Connect,
|
||||||
|
PermissionFlagsBits.Stream,
|
||||||
|
PermissionFlagsBits.UseVAD,
|
||||||
|
PermissionFlagsBits.Speak
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function that either creates a new custom channel or gets an existing one registered in the database.
|
* Function that either creates a new custom channel or gets an existing one registered in the database.
|
||||||
* @param {GuildMember} member The member that caused this event.
|
* @param {GuildMember} member The member that caused this event.
|
||||||
@ -29,13 +46,16 @@ const getChannel = async (member, guildChs, channel) => {
|
|||||||
// Create private channel with all permissions
|
// Create private channel with all permissions
|
||||||
const name = member.user.username;
|
const name = member.user.username;
|
||||||
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
|
const chName = `${name}${name.toLowerCase().endsWith('s') ? "'" : "'s"} channel`;
|
||||||
// Get permissions from parent
|
|
||||||
const vcPermOver = channel.parent.permissionOverwrites.cache.get(member.id);
|
|
||||||
const privCh = await guildChs.create({
|
const privCh = await guildChs.create({
|
||||||
name: chName,
|
name: chName,
|
||||||
parent: channel.parent,
|
parent: channel.parent,
|
||||||
type: ChannelType.GuildVoice,
|
type: ChannelType.GuildVoice,
|
||||||
permissionOverwrites: [vcPermOver]
|
permissionOverwrites: [
|
||||||
|
{
|
||||||
|
id: member.id,
|
||||||
|
allow: vcPermissionOverwrites
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save newly created channel
|
// Save newly created channel
|
||||||
@ -81,24 +101,26 @@ export const name = Events.VoiceStateUpdate;
|
|||||||
* @param {VoiceState} newState
|
* @param {VoiceState} newState
|
||||||
*/
|
*/
|
||||||
export async function execute(oldState, newState) {
|
export async function execute(oldState, newState) {
|
||||||
const { channel, member } = newState;
|
const { channel } = newState;
|
||||||
let step = 'delete';
|
await leftVoiceChat(oldState);
|
||||||
|
if (!channel) return;
|
||||||
|
|
||||||
|
// Find channel by id, return if not registered for customs
|
||||||
|
const createCh = await VoiceChannel.findOne({
|
||||||
|
where: {
|
||||||
|
id: channel.id,
|
||||||
|
create: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (createCh === null) return;
|
||||||
|
|
||||||
|
// Extract user data
|
||||||
|
const member = newState.member;
|
||||||
|
|
||||||
|
// Extract channel data
|
||||||
|
const channels = newState.guild.channels;
|
||||||
|
let step = 'create';
|
||||||
try {
|
try {
|
||||||
await leftVoiceChat(oldState);
|
|
||||||
if (!channel) return;
|
|
||||||
|
|
||||||
// Find channel by id, return if not registered for customs
|
|
||||||
const createCh = await VoiceChannel.findOne({
|
|
||||||
where: {
|
|
||||||
id: channel.id,
|
|
||||||
create: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (createCh === null) return;
|
|
||||||
|
|
||||||
step = 'create';
|
|
||||||
// Extract channel data
|
|
||||||
const channels = newState.guild.channels;
|
|
||||||
const privCh = await getChannel(member, channels, channel);
|
const privCh = await getChannel(member, channels, channel);
|
||||||
|
|
||||||
step = 'move to';
|
step = 'move to';
|
||||||
|
@ -37,7 +37,7 @@ export async function execute(reaction, user) {
|
|||||||
reaction.remove();
|
reaction.remove();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Missing permissions
|
// Missing permissions
|
||||||
console.error(error);
|
console.error(error)
|
||||||
await user.send('Unable to remove reaction. Please contact server staff.');
|
await user.send('Unable to remove reaction. Please contact server staff.');
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -66,11 +66,7 @@ const saveMessageData = async (id, role, emoji) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create database entry for pair
|
// Create database entry for pair
|
||||||
await RoleEmojiPair.create({
|
await RoleEmojiPair.create({ message: id, role: role.id, emoji: emoji.replace(/:(\s*[^:]*\s*):/, ":_:") });
|
||||||
message: id,
|
|
||||||
role: role.id,
|
|
||||||
emoji: emoji.replace(/:(\s*[^:]*\s*):/, ':_:')
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user