all repos — stealth-developers @ 43a6ea6a77ad7a662d493b0f020e52f86b72e076

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
import { kitten } from "@/client";
import { upsertUser } from "@/lib";
import { HaltExecution } from "@purrkit/router";
import { getActorByDiscordIdAndGuildDiscordId, upsertActor } from "@stealth-developers/db";

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;
}