From a1f303115f415eacad834401fe1926cd7b4d8d78 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 3 Feb 2024 21:00:15 -0300 Subject: [PATCH] Uhhh trying. TODO: User Command + Chat logs save --- bun.lockb | Bin 67487 -> 67487 bytes src/channel/Channel.ts | 2 +- src/data/user.ts | 7 +++++++ src/util/readline/commands.ts | 31 +++++++++++++++++++++++-------- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/bun.lockb b/bun.lockb index dcce92a7d04dea966baf744c3a10612bda0e3ca0..0816a0defae821d0e95039eff5c0082ae23357fa 100755 GIT binary patch delta 22 ecmbQ=&oaNCWy8}Q?2K{7dPaI?o8Ro%><0j8lL==4 delta 22 acmbQ=&oaNCWy8}Q>`V+`u=&l7&3*t~;|LP~ diff --git a/src/channel/Channel.ts b/src/channel/Channel.ts index b5136d8..c9aebc5 100644 --- a/src/channel/Channel.ts +++ b/src/channel/Channel.ts @@ -14,6 +14,7 @@ import { findSocketByPartID, socketsBySocketID } from "../ws/Socket"; import Crown from "./Crown"; import { ChannelList } from "./ChannelList"; import { config } from "./config"; +import { prisma } from "../data/prisma"; interface CachedKickban { userId: string; @@ -125,7 +126,6 @@ export class Channel extends EventEmitter { this.sendArray([outgoing]); this.chatHistory.push(outgoing); - try { if (msg.message.startsWith("/")) { this.emit("command", msg, socket); diff --git a/src/data/user.ts b/src/data/user.ts index c932664..5e523c1 100644 --- a/src/data/user.ts +++ b/src/data/user.ts @@ -13,6 +13,13 @@ export async function createUser( }); } +export async function getUsers() { + return await { + users: await prisma.user.findMany(), + count: await prisma.user.count() + } +} + export async function deleteUser(_id: string) { return await prisma.user.delete({ where: { id: _id } diff --git a/src/util/readline/commands.ts b/src/util/readline/commands.ts index 7433dae..a1aab29 100644 --- a/src/util/readline/commands.ts +++ b/src/util/readline/commands.ts @@ -1,5 +1,5 @@ import { ChannelList } from "../../channel/ChannelList"; -import { deleteUser } from "../../data/user"; +import { deleteUser, getUsers } from "../../data/user"; import Command from "./Command"; Command.addCommand( @@ -50,12 +50,27 @@ Command.addCommand( ); Command.addCommand( - new Command(["list", "ls"], "list", async msg => { - return ( - "Channels:\n- " + - ChannelList.getList() - .map(ch => ch.getID()) - .join("\n- ") - ); + new Command(["list", "ls"], "list ", async msg => { + if(msg.args.length > 1) { + if(msg.args[1] == "channels") { + return ( + "Channels:\n- " + + ChannelList.getList() + .map(ch => ch.getID()) + .join("\n- ") + ); + } else if (msg.args[1] == "users") { + var users = getUsers(); + return ( + "Users: "+await (await users).count+"\n- " + + (await users).users.forEach(async user => { + `\n- ${user.id}: ${user.name}` + }) + ); + } + } else { + return "list "; + } + }) );