ditto/scripts/admin-role.ts

39 lines
944 B
TypeScript
Raw Normal View History

2024-04-23 23:13:18 +00:00
import { NSchema } from '@nostrify/nostrify';
2024-05-14 23:51:35 +00:00
import { DittoDB } from '@/db/DittoDB.ts';
2024-04-23 23:13:18 +00:00
import { Conf } from '@/config.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
2024-05-15 13:18:31 +00:00
import { EventsDB } from '@/storages/EventsDB.ts';
2024-04-23 23:13:18 +00:00
import { nostrNow } from '@/utils.ts';
2024-05-14 23:51:35 +00:00
const kysely = await DittoDB.getInstance();
const eventsDB = new EventsDB(kysely);
2024-04-23 23:13:18 +00:00
const [pubkey, role] = Deno.args;
if (!NSchema.id().safeParse(pubkey).success) {
console.error('Invalid pubkey');
Deno.exit(1);
}
if (!['admin', 'user'].includes(role)) {
console.error('Invalid role');
Deno.exit(1);
}
const event = await new AdminSigner().signEvent({
kind: 30361,
tags: [
['d', pubkey],
['role', role],
// NIP-31: https://github.com/nostr-protocol/nips/blob/master/31.md
['alt', `User's account was updated by the admins of ${Conf.url.host}`],
],
content: '',
created_at: nostrNow(),
});
await eventsDB.event(event);
Deno.exit(0);