summary refs log tree commit diff
path: root/commands.ts
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-11-30 12:10:08 +0200
committerWlodekM <[email protected]>2024-11-30 12:10:08 +0200
commit6cb6085e508b3b72697924490bad517546bdec71 (patch)
treefea72feea7b524514a21a95bdf9153acc6cd4257 /commands.ts
parent7bf34fb819f12e551ee8e50dcfd7e0369a68eb8e (diff)
do stuff
Diffstat (limited to 'commands.ts')
-rw-r--r--commands.ts12
1 files changed, 8 insertions, 4 deletions
diff --git a/commands.ts b/commands.ts
index 095c534..8a93c8a 100644
--- a/commands.ts
+++ b/commands.ts
@@ -1,6 +1,7 @@
 import fs from "node:fs";
 import type User from "./user.ts";
 import type Server from "./server.ts";
+import { ChannelConfig } from "./server.ts";
 
 // NOTE - temporary, will make class later
 export type Command = {
@@ -23,10 +24,13 @@ export const commands: {[key: string]: Command} = {
             if (!args[0].startsWith("#")) return user.socket.send("Error: Channel not found, run /channels to see a list of channels.");
             if (!server.channels.includes(args[0].replace("#", ""))) return user.socket.send("Error: Channel not found, run /channels to see a list of channels.");
             sendInChannel(`${user.name()} left #${user.channel}.`, user.channel);
-            user.channel = args[0].replace("#", "");
+            const newChannel = args[0].replace("#", "")
+            console.info(`${user.name()} went to #${newChannel}`);
+            sendInChannel(`${user.name()} joined #${newChannel}!`, newChannel);
+            user.channel = newChannel;
             server.updateUsers();
-            console.info(`${user.name()} went to #${user.channel}`);
-            sendInChannel(`${user.name()} joined #${user.channel}!`, user.channel);
+            const channelConfig: ChannelConfig = server.config['channels-'+newChannel] as ChannelConfig;
+            user.socket.send(channelConfig?.motd ?? `You joined #${newChannel}`)
         },
     },
     channels: {
@@ -174,7 +178,7 @@ export function register(cmd: string, data: Command) {
 
 const commandFiles = fs
     .readdirSync("commands")
-    .filter((filename) => filename.endsWith(".js"))
+    .filter((filename) => filename.endsWith(".js") || filename.endsWith(".ts"))
     .map((file) => file.replace(/\.js$/gim, ""));
 for (let i = 0; i < commandFiles.length; i++) {
     const cmdName = commandFiles[i];