able to duplicate channel with only joining
All checks were successful
release-tag / release-image (push) Successful in 24s
All checks were successful
release-tag / release-image (push) Successful in 24s
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { Commands, type CommandsType } from "commands";
|
||||
import {
|
||||
ChannelType,
|
||||
Client,
|
||||
Events,
|
||||
IntentsBitField,
|
||||
VoiceState,
|
||||
type ButtonInteraction,
|
||||
type CacheType,
|
||||
type ChatInputCommandInteraction,
|
||||
@@ -17,6 +21,8 @@ import { GreetingService } from "actions/greeting/greeting.service";
|
||||
import { ActivityService } from "actions/activity/activity.service";
|
||||
import { DmService } from "actions/dm/dm.service";
|
||||
import { CustomMessageService } from "actions/customMessage/customMessage.service";
|
||||
import { DynamicChannelService } from "actions/dynamicChannel/dynamicChannel.service";
|
||||
import config from "config";
|
||||
|
||||
export default class DiscordController extends EventEmitter {
|
||||
private discordService!: DiscordService;
|
||||
@@ -27,6 +33,8 @@ export default class DiscordController extends EventEmitter {
|
||||
activityService: ActivityService;
|
||||
dmService: DmService;
|
||||
customMessageService: CustomMessageService;
|
||||
channelListeners = new Map();
|
||||
dynamicChannelService: DynamicChannelService;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -38,6 +46,9 @@ export default class DiscordController extends EventEmitter {
|
||||
this.activityService = new ActivityService();
|
||||
this.dmService = new DmService();
|
||||
this.customMessageService = new CustomMessageService();
|
||||
this.dynamicChannelService = new DynamicChannelService();
|
||||
|
||||
var channelListeners = new Map();
|
||||
// log when running
|
||||
client.once("ready", async () => {
|
||||
await this.setActivity();
|
||||
@@ -58,6 +69,58 @@ export default class DiscordController extends EventEmitter {
|
||||
client.on("guildMemberAdd", async (member) => {
|
||||
await this.greetingService.welcome(member);
|
||||
});
|
||||
|
||||
client.on(Events.VoiceStateUpdate, async (oldState: VoiceState, newState: VoiceState) => {
|
||||
// check if user joined a vc
|
||||
if (!oldState.channelId && newState.channelId) {
|
||||
// check if right vc
|
||||
if (newState.channelId === config.discord.vchannelIdForTwo || newState.channelId === config.discord.vchannelIdForThree || newState.channelId === config.discord.vchannelIdForFour || newState.channelId === config.discord.vchannelIdForGroup) {
|
||||
const channel = newState.channel;
|
||||
if (!channel) {
|
||||
console.error("channel not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// create new channel with same settings
|
||||
/*const newChannel = await channel.clone({
|
||||
name: channel.name + "; " + newState.member?.displayName,
|
||||
position: channel.position
|
||||
});*/
|
||||
|
||||
|
||||
const newChannel = await this.dynamicChannelService.createChannel(oldState, newState, channel);
|
||||
|
||||
// move user in new channel
|
||||
await newState.setChannel(newChannel);
|
||||
|
||||
// create specific listener for channel
|
||||
const channelListener = async (oldState: VoiceState, newState: VoiceState) => {
|
||||
/*if (oldState.channelId === newChannel.id || newState.channelId === newChannel.id) {
|
||||
// check if channel empty
|
||||
if (newChannel.members.size === 0) {
|
||||
newChannel.delete()
|
||||
.catch(console.error);
|
||||
// delete listener for this channel
|
||||
client.removeListener(Events.VoiceStateUpdate, channelListener);
|
||||
channelListeners.delete(newChannel.id);
|
||||
}
|
||||
}*/
|
||||
channelListeners = await this.dynamicChannelService.deleteChannel(oldState, newState, newChannel, channelListeners, channelListener);
|
||||
|
||||
};
|
||||
// save listener in map
|
||||
channelListeners.set(newChannel.id, channelListener);
|
||||
|
||||
// add listener
|
||||
client.on(Events.VoiceStateUpdate, channelListener);
|
||||
|
||||
} catch (error) {
|
||||
console.error("error while duplicating channel", error);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async setActivity() {
|
||||
|
||||
Reference in New Issue
Block a user