adding a cmd

This commit is contained in:
Daniel 2024-02-04 17:01:17 -03:00
parent ef7d326360
commit 29533d8aff
2 changed files with 46 additions and 2 deletions

View File

@ -247,6 +247,22 @@ export class Channel extends EventEmitter {
return this.settings[setting];
}
/**
* Updapte a User.
* @param id Socket that is getting
* @returns undefined
*/
public updateUser(id: string): void {
for (const socket of socketsBySocketID.values()) {
if(this.hasUser(id)) {
if (socket.getParticipantID() == id) {
socket.userset(socket.getParticipant()?.name, socket.getParticipant()?.color, socket.getParticipant()?.rank == "admin")
}
}
}
}
/**
* Make a socket join this channel
* @param socket Socket that is joining

View File

@ -1,7 +1,7 @@
import { create } from "domain";
import { ChannelList } from "../../channel/ChannelList";
import { prisma } from "../../data/prisma";
import { deleteUser, getUsers, createUser } from "../../data/user";
import { deleteUser, getUsers, createUser, updateUser } from "../../data/user";
import { config } from "../../ws/usersConfig";
import Command from "./Command";
@ -40,6 +40,34 @@ Command.addCommand(
})
);
Command.addCommand(
new Command(["set", "userset"], "set <tag|color|name> <set to wat>", async msg => {
if(msg.args.length !> 4) return "set <_id> <tag|color|name> <set to wat>";
var set = msg.args[3]
var property = msg.args[2]
var id = msg.args[1]
if(property == "tag" || property == "color" || property == "name") {
var part = await prisma.user.findFirst({where:{ id:id }})
if(!part) return "invalid user id.";
updateUser(id, {
[property]: set
})
ChannelList.getList().forEach(async ch => {
if (ch.hasUser(id)) {
var part = await prisma.user.findFirst({where:{ id:id }})
if(part) {
ch.updateUser(id)
}
}
})
return "Updated user, maybe sucessfully";
} else {
return "set <_id> <tag|color|name> <set to wat> - Especify what you're setting"
}
})
);
Command.addCommand(
new Command(["stop", "exit"], "stop", msg => {
process.exit();
@ -71,7 +99,7 @@ Command.addCommand(
return("User Created. : "+JSON.stringify(checkCreated));
}
} else {
return("Usage: createuser <id> <token> <tag> <rank>")
return("Usage: createuser <id: String> <token: String> <tag : Object> <rank: member|admin>")
}
})
);