all repos — stealth-developers @ b7a615a91bcbb87e449d2d1032ab961b30a107da

apps/bot/src/middleware/index.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
import { kitten } from "@/client";
import { upsertUser } from "@/lib";
import { HaltExecution } from "@purrkit/router";

const base = kitten.builder();

export const getDbActor = base.use(async (interaction) => {
	if (!interaction.guild) throw new HaltExecution("This command can only be run in a guild.");

	const actor = await upsertUser(interaction.user, interaction.guild);
	if (!actor) throw new HaltExecution("Failed to add you to the database. Please try again.");

	return actor;
});