commands/ward-web.ts
2.0 KB · sha256:3662d84fbd083ff260a24231b1d0fdd212ea8d15d303bc3c441d352a85678edc
import { err, ok, raw, requirePerm } from "../lib/format";
import { issueToken, revokeToken } from "../lib/web-auth";
import { PERM } from "./ward";
@Command("ward web token", {
description: "Issue a bearer token for the Ward web dashboard",
})
export class WardWebToken {
@Run
run(ctx: CommandCtx) {
if (!requirePerm(ctx, PERM.web)) return;
const sender = ctx.sender;
if (typeof sender.getUniqueId !== "function") {
err(
sender,
"Only players can mint tokens (token is bound to your UUID).",
);
return;
}
const player = sender;
const uuid = String(player.getUniqueId());
const name = String(player.getName());
const token = issueToken(uuid, name);
raw(sender, "<dark_gray>━━━━━━━━━━━━━━━━━━━━━━━━");
raw(
sender,
"<gradient:#9b87f5:#5b3df5>Ward web token</gradient> <dark_gray>(24h)",
);
raw(
sender,
`<click:copy_to_clipboard:'${token}'>` +
`<hover:show_text:'<gray>Token: <white>${token}<newline><dark_gray>(hidden in chat · click to copy)'>` +
`<gradient:#9b87f5:#5b3df5>→ click here to copy your token ←</gradient>` +
`</hover></click>`,
);
raw(
sender,
"<dark_gray>(hover to reveal · token never echoed to chat)",
);
raw(sender, "<dark_gray>━━━━━━━━━━━━━━━━━━━━━━━━");
raw(
sender,
`<gray>Permissions on your account decide what you can do. Revoke with <white>/ward web revoke`,
);
}
}
@Command("ward web revoke", {
description: "Revoke your active dashboard token",
})
export class WardWebRevoke {
@Run
run(ctx: CommandCtx) {
if (!requirePerm(ctx, PERM.web)) return;
const sender = ctx.sender;
if (typeof sender.getUniqueId !== "function") {
err(sender, "Only players have tokens to revoke.");
return;
}
const uuid = String(sender.getUniqueId());
revokeToken(uuid);
ok(sender, "your dashboard token has been revoked");
}
}