Add deleteallusers readline command

This commit is contained in:
Hri7566 2024-10-16 02:07:41 -04:00
parent b86d86b3f2
commit dd73e303a6
4 changed files with 21 additions and 7 deletions

2
public

@ -1 +1 @@
Subproject commit 1dc00c7f885ac919a1bda7d4c749d33bd594c42f Subproject commit a8a0182686cec166c3042697c639c5ca8b6acf6b

View File

@ -35,7 +35,7 @@ export async function getUsers() {
return { return {
users: await prisma.user.findMany(), users: await prisma.user.findMany(),
count: await prisma.user.count() count: await prisma.user.count()
} };
} }
export async function deleteUser(_id: string) { export async function deleteUser(_id: string) {
@ -44,6 +44,10 @@ export async function deleteUser(_id: string) {
}); });
} }
export async function deleteAllUsers() {
return await prisma.user.deleteMany();
}
export async function readUser(_id: string) { export async function readUser(_id: string) {
try { try {
const data = await prisma.user.findUnique({ const data = await prisma.user.findUnique({

View File

@ -50,9 +50,6 @@ export function createSocketID() {
} }
export function createColor(_id: string) { export function createColor(_id: string) {
logger.debug(
"Creating color for " + _id + " using method " + config.colorGeneration
);
if (config.colorGeneration == "random") { if (config.colorGeneration == "random") {
return "#" + Math.floor(Math.random() * 16777215).toString(16); return "#" + Math.floor(Math.random() * 16777215).toString(16);
} else if (config.colorGeneration == "sha256") { } else if (config.colorGeneration == "sha256") {
@ -73,7 +70,6 @@ export function createColor(_id: string) {
const g = output.readUInt8(1) + 0x20; const g = output.readUInt8(1) + 0x20;
const b = output.readUInt8(2); const b = output.readUInt8(2);
logger.debug("Colors:", r, g, b);
return ( return (
"#" + "#" +
r.toString(16).padStart(2, "0") + r.toString(16).padStart(2, "0") +

View File

@ -1,6 +1,6 @@
import { getRoles, giveRole, removeRole } from "~/data/role"; import { getRoles, giveRole, removeRole } from "~/data/role";
import { ChannelList } from "../../channel/ChannelList"; import { ChannelList } from "../../channel/ChannelList";
import { deleteUser, getUsers } from "../../data/user"; import { deleteAllUsers, deleteUser, getUsers } from "../../data/user";
import Command from "./Command"; import Command from "./Command";
import { import {
addRolePermission, addRolePermission,
@ -10,6 +10,7 @@ import {
removeRolePermission removeRolePermission
} from "~/data/permissions"; } from "~/data/permissions";
import { builtinTags, removeTag, setBuiltinTag } from "../tags"; import { builtinTags, removeTag, setBuiltinTag } from "../tags";
import logger from "./logger";
Command.addCommand( Command.addCommand(
new Command(["help", "h", "commands", "cmds"], "help", msg => { new Command(["help", "h", "commands", "cmds"], "help", msg => {
@ -198,3 +199,16 @@ Command.addCommand(
} }
}) })
); );
Command.addCommand(
new Command(["deleteallusers"], "deleteallusers [confirm]", async msg => {
if (!msg.args[1])
return `Are you sure this is what you want? Type "deleteallusers confirm" to confirm:`;
if (msg.args[1] !== "confirm") return "Invalid response";
logger.info("Deletion info:", await deleteAllUsers());
return "All user data successfully deleted.";
})
);