summary refs log tree commit diff
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-11-30 14:24:39 +0200
committerWlodekM <[email protected]>2024-11-30 14:24:39 +0200
commit714a4189eb02051ddd330513048b07b3be070e27 (patch)
tree64112d5ce9d2b433cc4be0adf561ac128a3d84b5
parentf37e3537adb59f2b724259a1720295756eb94277 (diff)
do stuff 3
-rw-r--r--commands.ts16
-rw-r--r--commands/ban.ts (renamed from commands/ban.js)7
-rw-r--r--commands/kick.ts (renamed from commands/kick.js)6
-rw-r--r--commands/motd.ts (renamed from commands/motd.js)6
-rw-r--r--lib.ts (renamed from lib.js)6
-rw-r--r--main.ts (renamed from newindex.js)0
-rw-r--r--oldindex.js2
-rw-r--r--ranks.ts (renamed from ranks.js)0
-rw-r--r--user.ts2
9 files changed, 29 insertions, 16 deletions
diff --git a/commands.ts b/commands.ts
index fbde383..e416aad 100644
--- a/commands.ts
+++ b/commands.ts
@@ -3,14 +3,21 @@ import type User from "./user.ts";
 import type Server from "./server.ts";
 import { ChannelConfig } from "./server.ts";
 
+export type CommandFnArgs = {
+    user: User,
+    server: Server,
+    args: string[],
+    sendInChannel: (msg: string, channel: string, server?: Server) => void,
+    commands: {[key: string]: Command}
+}
+
 // NOTE - temporary, will make class later
 export type Command = {
     name: string,
     usage?: string,
     description: string,
     aliases: string[],
-    command: ({ user, server, args, sendInChannel, commands }:
-        { user: User, server: Server, args: string[], sendInChannel: (msg: string, channel: string, server?: Server) => void, commands: {[key: string]: Command} }) => void
+    command: ({ user, server, args, sendInChannel, commands }: CommandFnArgs) => void
 }
 
 export const commands: {[key: string]: Command} = {
@@ -178,8 +185,9 @@ export function register(cmd: string, data: Command) {
 
 const commandFiles = fs
     .readdirSync("commands")
-    .filter((filename) => filename.endsWith(".js") || filename.endsWith(".ts"))
-    .map((file) => file.replace(/\.js$/gim, ""));
+    .filter((filename: string) => filename.endsWith(".js") || filename.endsWith(".ts"))
+    .map((file: string) => file.replace(/\.js$/gim, ""));
+
 for (let i = 0; i < commandFiles.length; i++) {
     const cmdName = commandFiles[i];
     const cmd = (await import(`./commands/${cmdName}.js`)).default;
diff --git a/commands/ban.js b/commands/ban.ts
index 584b4d0..77d23b5 100644
--- a/commands/ban.js
+++ b/commands/ban.ts
@@ -1,14 +1,15 @@
 import fs from "node:fs";
+import { CommandFnArgs } from "../commands.ts"
 
 export default {
     name: "ban",
     aliases: [],
-    command: function ({ user, server, args }) {
+    command: function ({ user, server, args }: CommandFnArgs) {
         if(!user.admin) return user.socket.send("You are not admin");
         if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found");
-        let theUser = Object.values(server.users).find(a => a.username == args[0]);
+        const theUser = Object.values(server.users).find(a => a.username == args[0]);
         theUser.socket.send('you were kicked because you were banned, L');
-        let ipBanList = JSON.parse(String(fs.readFileSync("db/bannedIps.json")));
+        const ipBanList = JSON.parse(String(fs.readFileSync("db/bannedIps.json")));
         ipBanList[theUser.ip] = args[1] ?? 'reason';
         ipBanList['account:'+args[0]] = args[1] ?? 'reason';
         theUser.socket.close(1003, "Kicked");
diff --git a/commands/kick.js b/commands/kick.ts
index accadb0..60568ed 100644
--- a/commands/kick.js
+++ b/commands/kick.ts
@@ -1,10 +1,12 @@
+import { CommandFnArgs } from "../commands.ts"
+
 export default {
     name: "kick",
     aliases: [],
-    command: function ({ user, server, args }) {
+    command: function ({ user, server, args }: CommandFnArgs) {
         if(!user.admin) return user.socket.send("You are not admin");
         if(!server.accounts.checkAccount(args[0])) return user.socket.send("Account not found");
-        let theUser = Object.values(server.users).find(a => a.username == args[0]);
+        const theUser = Object.values(server.users).find(a => a.username == args[0]);
         theUser.socket.send('you were kicked')
         theUser.socket.close(1003, "Kicked");
     },
diff --git a/commands/motd.js b/commands/motd.ts
index a4e7fde..43293c9 100644
--- a/commands/motd.js
+++ b/commands/motd.ts
@@ -1,7 +1,9 @@
+import { CommandFnArgs } from "../commands.ts"
+
 export default {
     name: "motd",
     aliases: [],
-    command: function ({ user, server }) {
-        user.socket.send("MOTD: " + server.format(server.config.motd));
+    command: function ({ user, server }: CommandFnArgs) {
+        user.socket.send("MOTD: " + server.format(server.config.server.motd));
     },
 };
diff --git a/lib.js b/lib.ts
index 9038650..1103206 100644
--- a/lib.js
+++ b/lib.ts
@@ -4,11 +4,11 @@
  * if min isn't an integer) and no greater than max (or the next integer
  * lower than max if max isn't an integer).
  * Using Math.round() will give you a non-uniform distribution!
- * @param {Number} min Min number
- * @param {Number} max Max number
+ * @param min Min number
+ * @param max Max number
  * @returns {Number}
  */
-export function getRandomInt(min, max) {
+export function getRandomInt(min: number, max: number) {
     min = Math.ceil(min);
     max = Math.floor(max);
     return Math.floor(Math.random() * (max - min + 1)) + min;
diff --git a/newindex.js b/main.ts
index 3e07868..3e07868 100644
--- a/newindex.js
+++ b/main.ts
diff --git a/oldindex.js b/oldindex.js
index 8acaa19..6e488e5 100644
--- a/oldindex.js
+++ b/oldindex.js
@@ -1,5 +1,5 @@
 import { WebSocketServer } from "ws";
-import { getRandomInt } from "./lib.js";
+import { getRandomInt } from "./lib.ts";
 import { profanity } from "@2toad/profanity";
 import { commands } from "./commands.ts";
 import * as accounts from "./accounts.ts";
diff --git a/ranks.js b/ranks.ts
index 78cab46..78cab46 100644
--- a/ranks.js
+++ b/ranks.ts
diff --git a/user.ts b/user.ts
index 910e8a4..c85c2f6 100644
--- a/user.ts
+++ b/user.ts
@@ -1,6 +1,6 @@
 // because why not make *more files
 
-import { getRandomInt } from "./lib.js";
+import { getRandomInt } from "./lib.ts";
 import cuid2 from "@paralleldrive/cuid2";
 import type { WebSocket } from 'ws'
 import type { IncomingMessage } from "node:http";