summaryrefslogtreecommitdiff
path: root/packages/gateway/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gateway/src')
-rw-r--r--packages/gateway/src/index.ts1
-rw-r--r--packages/gateway/src/listeners/index.ts2
-rw-r--r--packages/gateway/src/listeners/moderationAgent/utilities.ts2
-rw-r--r--packages/gateway/src/listeners/voiceConnection.ts67
4 files changed, 71 insertions, 1 deletions
diff --git a/packages/gateway/src/index.ts b/packages/gateway/src/index.ts
index 2998a6b..0bb9597 100644
--- a/packages/gateway/src/index.ts
+++ b/packages/gateway/src/index.ts
@@ -11,6 +11,7 @@ const client = new Client({
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
+ GatewayIntentBits.GuildVoiceStates,
],
});
diff --git a/packages/gateway/src/listeners/index.ts b/packages/gateway/src/listeners/index.ts
index 2637d2f..c640b25 100644
--- a/packages/gateway/src/listeners/index.ts
+++ b/packages/gateway/src/listeners/index.ts
@@ -5,8 +5,10 @@ import { handleChannelDeletion } from "./channelDeletion";
import { handleMessageDeletion } from "./messageDeletion";
import { handleMessageEdit } from "./messageEdit";
import { handleClientReady } from "./clientReady";
+import { handleVoiceConnection } from "./voiceConnection";
export const handleListeners = (client: Client) => {
+ handleVoiceConnection(client);
handleClientReady(client);
handleMessageCreate(client);
handleRoleProtection(client);
diff --git a/packages/gateway/src/listeners/moderationAgent/utilities.ts b/packages/gateway/src/listeners/moderationAgent/utilities.ts
index ec3201f..eb520c7 100644
--- a/packages/gateway/src/listeners/moderationAgent/utilities.ts
+++ b/packages/gateway/src/listeners/moderationAgent/utilities.ts
@@ -5,7 +5,7 @@ export const fetchMessageContext = async (
channel: TextChannel | ThreadChannel,
messageId: string,
): Promise<string> => {
- if (MESSAGE_HISTORY_SIZE === 0) return "";
+ if (MESSAGE_HISTORY_SIZE <= 0) return "";
try {
const messages = await channel.messages.fetch({
diff --git a/packages/gateway/src/listeners/voiceConnection.ts b/packages/gateway/src/listeners/voiceConnection.ts
new file mode 100644
index 0000000..04f2b32
--- /dev/null
+++ b/packages/gateway/src/listeners/voiceConnection.ts
@@ -0,0 +1,67 @@
+import { Client, Events } from "discord.js";
+import {
+ joinVoiceChannel,
+ VoiceConnectionStatus,
+ createAudioPlayer,
+} from "@discordjs/voice";
+
+const VOICE_CHANNEL_ID = "1422049438863589487";
+
+export const handleVoiceConnection = (client: Client) => {
+ client.once(Events.ClientReady, async () => {
+ const voiceChannel = client.channels.cache.get(VOICE_CHANNEL_ID);
+
+ if (!voiceChannel || !voiceChannel.isVoiceBased()) {
+ console.error(
+ `Voice channel ${VOICE_CHANNEL_ID} not found or is not a voice channel`,
+ );
+
+ return;
+ }
+
+ try {
+ const connection = joinVoiceChannel({
+ channelId: voiceChannel.id,
+ guildId: voiceChannel.guildId!,
+ adapterCreator: voiceChannel.guild.voiceAdapterCreator,
+ });
+ const player = createAudioPlayer();
+
+ connection.subscribe(player);
+ connection.on(VoiceConnectionStatus.Disconnected, () => {
+ setTimeout(() => {
+ try {
+ const newConnection = joinVoiceChannel({
+ channelId: voiceChannel.id,
+ guildId: voiceChannel.guildId!,
+ adapterCreator: voiceChannel.guild.voiceAdapterCreator,
+ });
+ const newPlayer = createAudioPlayer();
+
+ newConnection.subscribe(newPlayer);
+ newConnection.on(VoiceConnectionStatus.Disconnected, () => {
+ setTimeout(() => {
+ handleVoiceConnection(client);
+ }, 5000);
+ });
+ } catch (error) {
+ console.error("Failed to reconnect to voice channel:", error);
+ setTimeout(() => {
+ handleVoiceConnection(client);
+ }, 10000);
+ }
+ }, 5000);
+ });
+ connection.on(VoiceConnectionStatus.Destroyed, () => {
+ setTimeout(() => {
+ handleVoiceConnection(client);
+ }, 5000);
+ });
+ } catch (error) {
+ console.error("Failed to connect to voice channel:", error);
+ setTimeout(() => {
+ handleVoiceConnection(client);
+ }, 10000);
+ }
+ });
+};