A chill Bluesky bot, with responses powered by Gemini.
at main 1.3 kB view raw
1import { interactions } from "../db/schema"; 2import type { Post } from "@skyware/bot"; 3import { desc, notInArray } from "drizzle-orm"; 4import { env } from "../env"; 5import db from "../db"; 6 7export function isAuthorizedUser(did: string) { 8 return env.AUTHORIZED_USERS == null 9 ? true 10 : env.AUTHORIZED_USERS.includes(did as any); 11} 12 13export async function logInteraction( 14 post: Post, 15 options: { 16 responseText: string | null; 17 wasMuted: boolean; 18 }, 19): Promise<void> { 20 await db.insert(interactions).values([ 21 { 22 uri: post.uri, 23 did: post.author.did, 24 post: post.text, 25 response: options.responseText, 26 muted: options.wasMuted, 27 }, 28 ]); 29 30 console.log(`Logged interaction, initiated by @${post.author.handle}`); 31} 32 33export async function getRecentInteractions(did: string, thread: Post[]) { 34 const threadUris = thread.map((p) => p.uri); 35 36 const recentInteractions = await db.query.interactions.findMany({ 37 where: (interactions, { eq, and, notInArray }) => 38 and( 39 eq(interactions.did, did), 40 notInArray(interactions.uri, threadUris), 41 ), 42 orderBy: (interactions, { desc }) => [desc(interactions.created_at)], 43 limit: 5, 44 }); 45 46 return recentInteractions.map((i) => ({ 47 post: i.post, 48 response: i.response, 49 })); 50}