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:
parent
6193865220
commit
3f7864be1b
52
src/actions/dynamicChannel/dynamicChannel.service.ts
Normal file
52
src/actions/dynamicChannel/dynamicChannel.service.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import config from "config";
|
||||
import client from "lib/client";
|
||||
import { getRandomInt } from "lib/utils";
|
||||
import { } from "./dynamicChannel.components.ts";
|
||||
import {
|
||||
Client,
|
||||
EmbedBuilder,
|
||||
type Message,
|
||||
type CacheType,
|
||||
type GuildMember,
|
||||
type Interaction,
|
||||
type OmitPartialGroupDMChannel,
|
||||
VoiceState,
|
||||
VoiceChannel,
|
||||
StageChannel,
|
||||
Events,
|
||||
type VoiceBasedChannel,
|
||||
} from "discord.js";
|
||||
|
||||
export class DynamicChannelService {
|
||||
async handleInteraction(interaction: Interaction<CacheType>) {
|
||||
// todo
|
||||
}
|
||||
|
||||
async createChannel(oldState: VoiceState, newState: VoiceState, channel: VoiceBasedChannel): Promise<StageChannel | VoiceChannel> {
|
||||
console.log("createChannel()");
|
||||
|
||||
const newChannel = await channel.clone({
|
||||
name: channel.name + " " + newState.member?.displayName,
|
||||
position: channel.position
|
||||
});
|
||||
|
||||
return newChannel;
|
||||
}
|
||||
|
||||
async deleteChannel(oldState: VoiceState, newState: VoiceState, newChannel: StageChannel | VoiceChannel, channelListeners: Map<any, any>, channelListener: (oldState: VoiceState, newState: VoiceState) => void) {
|
||||
|
||||
console.log("deleteChannel()");
|
||||
|
||||
if (oldState.channelId === newChannel.id || newState.channelId === newChannel.id) {
|
||||
|
||||
if (newChannel.members.size === 0) {
|
||||
newChannel.delete()
|
||||
.catch(console.error);
|
||||
|
||||
client.removeListener(Events.VoiceStateUpdate, channelListener);
|
||||
channelListeners.delete(newChannel.id);
|
||||
}
|
||||
}
|
||||
return channelListeners;
|
||||
}
|
||||
}
|
@ -8,31 +8,31 @@ export const dmAcceptedContent = `huhu! du wurdest als lernende:r akzeptiert :3\
|
||||
|
||||
export function getWelcomeContent(member: GuildMember) {
|
||||
const welcomeContents = [
|
||||
`willkommen auf dem server, ${member}! 💕`,
|
||||
`willkommen auf dem server, ${member}! fuehl dich wie zuhause💕`,
|
||||
`hey ${member}! schoen, dass du hier bist! 😊`,
|
||||
`hi ${member}, willkommen! viel spass hier! 💖`,
|
||||
`willkommen, ${member}! schoen, dass du da bist! 🥳`,
|
||||
`willkommen, ${member}! schoen, dass du da bist! :3`,
|
||||
`moin ${member}! viel spass im server! c:`,
|
||||
`hey ${member}, herzlich willkommen! fuehl dich wie zu hause! <3`,
|
||||
`hi ${member}! cool, dass du da bist! 👏`,
|
||||
`hi ${member}! cool, dass du da bist! <3`,
|
||||
`willkommen, ${member}! wir freuen uns, dass du hier bist! 💕`,
|
||||
`hey ${member}! schoen, dass du bei uns bist! :3`,
|
||||
`willkommen auf dem server, ${member}! viel spass hier! ✨`,
|
||||
`hi ${member}, super, dass du dabei bist! 😊`,
|
||||
`hi ${member}, super, dass du dabei bist! :3`,
|
||||
`hey ${member}, willkommen bei uns! 💖`,
|
||||
`moin ${member}! schoen, dass du dabei bist! 🥳`,
|
||||
`moin ${member}! schoen, dass du dabei bist! :)`,
|
||||
`hi ${member}, willkommen in unserer kleinen community! ✨`,
|
||||
`willkommen, ${member}! fuehl dich wie zu hause! 💕`,
|
||||
`hey ${member}, schoen, dass du uns gefunden hast! 😊`,
|
||||
`hi ${member}, willkommen in unserer runde! 🎉`,
|
||||
`hey ${member}, schoen, dass du uns gefunden hast! <333`,
|
||||
`hi ${member}, willkommen in unserer runde! c:`,
|
||||
`willkommen, ${member}! schoen, dass du hier bist! 💖`,
|
||||
`moin ${member}! lass uns zusammen spass haben! ✨`,
|
||||
`hey ${member}, herzlich willkommen bei uns! 😊`,
|
||||
`hi ${member}! schoen, dass du dabei bist! 💕`,
|
||||
`willkommen auf dem server, ${member}! wir freuen uns auf dich! 🎉`,
|
||||
`willkommen auf dem server, ${member}! wir freuen uns auf dich! <3`,
|
||||
`hey ${member}, schoen, dass du da bist! ✨`,
|
||||
`hi ${member}, willkommen! fuehl dich wie zu hause! 💖`,
|
||||
`willkommen, ${member}! lass uns gemeinsam eine tolle zeit haben! 😊`,
|
||||
`willkommen, ${member}! lass uns gemeinsam eine tolle zeit haben! :3`,
|
||||
];
|
||||
return welcomeContents[Math.floor(Math.random() * welcomeContents.length)];
|
||||
}
|
@ -5,16 +5,22 @@ export default {
|
||||
|
||||
// avocadi
|
||||
serverID: process.env.DISCORD_SERVER_ID || "",
|
||||
// texxt channel
|
||||
channelIdBot: process.env.DISCORD_CHANNEL_ID_BOT || "",
|
||||
channelIdFeedback: process.env.DISCORD_CHANNEL_ID_FEEDBACK || "",
|
||||
channelIdNotification: process.env.DISCORD_CHANNEL_ID_NOTIFICATION || "",
|
||||
channelIdWelcome: process.env.DISCORD_CHANNEL_ID_WELCOME || "",
|
||||
channelIdRules: process.env.DISCORD_CHANNEL_ID_RULE || "",
|
||||
channelIdNews: process.env.DISCORD_CHANNEL_ID_NEWS || "",
|
||||
channelIdIntroduction: process.env.DISCORD_CHANNEL_ID_INTRODUCTION || "",
|
||||
|
||||
channelIdOffTopic: process.env.DISCORD_CHANNEL_ID_OFF_TOPIC || "",
|
||||
channelIdFeedback: process.env.DISCORD_CHANNEL_ID_FEEDBACK || "",
|
||||
channelIdHelp: process.env.DISCORD_CHANNEL_ID_HELP || "",
|
||||
// voice channel#
|
||||
vchannelIdForTwo: process.env.DISCORD_VCHANNEL_ID_FOR_TWO || "",
|
||||
vchannelIdForThree: process.env.DISCORD_VCHANNEL_ID_FOR_THREE || "",
|
||||
vchannelIdForFour: process.env.DISCORD_VCHANNEL_ID_FOR_FOUR || "",
|
||||
vchannelIdForGroup: process.env.DISCORD_VCHANNEL_ID_FOR_GROUP || "",
|
||||
// roles
|
||||
roleStudy: process.env.PEOPLE || "",
|
||||
|
||||
// other
|
||||
|
@ -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() {
|
||||
|
@ -1,28 +1,23 @@
|
||||
import config from "config";
|
||||
import {
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
Partials,
|
||||
IntentsBitField,
|
||||
} from "discord.js";
|
||||
import { Client, GatewayIntentBits, Partials, ChannelType, Events, IntentsBitField } from "discord.js";
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
IntentsBitField.Flags.Guilds,
|
||||
IntentsBitField.Flags.GuildMembers,
|
||||
IntentsBitField.Flags.GuildModeration,
|
||||
IntentsBitField.Flags.GuildMessages,
|
||||
IntentsBitField.Flags.GuildMessageReactions,
|
||||
IntentsBitField.Flags.GuildMessagePolls,
|
||||
IntentsBitField.Flags.MessageContent,
|
||||
IntentsBitField.Flags.DirectMessages,
|
||||
IntentsBitField.Flags.DirectMessageReactions,
|
||||
IntentsBitField.Flags.DirectMessageTyping,
|
||||
IntentsBitField.Flags.DirectMessagePolls,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
],
|
||||
partials: [Partials.Channel, Partials.Message],
|
||||
intents: [IntentsBitField.Flags.Guilds,
|
||||
IntentsBitField.Flags.GuildMembers,
|
||||
IntentsBitField.Flags.GuildModeration,
|
||||
IntentsBitField.Flags.GuildMessages,
|
||||
IntentsBitField.Flags.GuildMessageReactions,
|
||||
IntentsBitField.Flags.GuildMessagePolls,
|
||||
IntentsBitField.Flags.MessageContent,
|
||||
IntentsBitField.Flags.DirectMessages,
|
||||
IntentsBitField.Flags.DirectMessageReactions,
|
||||
IntentsBitField.Flags.DirectMessageTyping,
|
||||
IntentsBitField.Flags.DirectMessagePolls,
|
||||
GatewayIntentBits.DirectMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildVoiceStates,],
|
||||
partials: [Partials.Channel, Partials.Message]
|
||||
});
|
||||
|
||||
await client.login(config.discord.token);
|
||||
|
Loading…
x
Reference in New Issue
Block a user