Uhhh trying. TODO: User Command + Chat logs save

This commit is contained in:
Daniel 2024-02-03 21:00:15 -03:00
parent 41ad34be05
commit a1f303115f
4 changed files with 31 additions and 9 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -14,6 +14,7 @@ import { findSocketByPartID, socketsBySocketID } from "../ws/Socket";
import Crown from "./Crown"; import Crown from "./Crown";
import { ChannelList } from "./ChannelList"; import { ChannelList } from "./ChannelList";
import { config } from "./config"; import { config } from "./config";
import { prisma } from "../data/prisma";
interface CachedKickban { interface CachedKickban {
userId: string; userId: string;
@ -125,7 +126,6 @@ export class Channel extends EventEmitter {
this.sendArray([outgoing]); this.sendArray([outgoing]);
this.chatHistory.push(outgoing); this.chatHistory.push(outgoing);
try { try {
if (msg.message.startsWith("/")) { if (msg.message.startsWith("/")) {
this.emit("command", msg, socket); this.emit("command", msg, socket);

View File

@ -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) { export async function deleteUser(_id: string) {
return await prisma.user.delete({ return await prisma.user.delete({
where: { id: _id } where: { id: _id }

View File

@ -1,5 +1,5 @@
import { ChannelList } from "../../channel/ChannelList"; import { ChannelList } from "../../channel/ChannelList";
import { deleteUser } from "../../data/user"; import { deleteUser, getUsers } from "../../data/user";
import Command from "./Command"; import Command from "./Command";
Command.addCommand( Command.addCommand(
@ -50,12 +50,27 @@ Command.addCommand(
); );
Command.addCommand( Command.addCommand(
new Command(["list", "ls"], "list", async msg => { new Command(["list", "ls"], "list <channels, users>", async msg => {
if(msg.args.length > 1) {
if(msg.args[1] == "channels") {
return ( return (
"Channels:\n- " + "Channels:\n- " +
ChannelList.getList() ChannelList.getList()
.map(ch => ch.getID()) .map(ch => ch.getID())
.join("\n- ") .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 <channels, users>";
}
}) })
); );