discord-botindex.ts4 matches
2import { Hono } from "https://esm.sh/hono@3.12.5";
3import { cors } from "https://esm.sh/@hono/cors@0.0.8";
4import { initializeDatabase } from "./database.ts";
5import { fetchAndStoreDMs } from "./discord-client.ts";
6import { handleDiscordInteractionRequest } from "./discord-interactions.ts";
20async function initializeServices() {
21try {
22// Initialize the database
23await initializeDatabase();
24log("Database initialized successfully", "info");
25
26// Initialize Anthropic client
discord-botdatabase.ts9 matches
1// Database adapter for Val.town SQLite
2import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
3import { extractUrls, log } from "../shared/utils.ts";
1920/**
21* Initialize the database schema
22*/
23export async function initializeDatabase() {
24try {
25// Create messages table
102}
103
104log("Database initialized successfully", "info");
105return true;
106} catch (error) {
107log(`Error initializing database: ${error.message}`, "error");
108throw error;
109}
111112/**
113* Save messages to the database
114* @param messages - Array of message objects to save
115*/
168}
169
170log(`Saved ${savedCount} of ${messages.length} messages to database`, "info");
171return savedCount;
172} catch (error) {
177178/**
179* Get messages from the database, with optional filtering
180* @param filters - Optional filters for messages
181* @returns Array of message objects
239240/**
241* Get links from the database, with optional filtering
242* @param filters - Optional filters for links
243* @returns Array of link objects
discord-botdiscord-client.ts2 matches
1// Discord client for Val.town
2import { saveDMMessages } from "./database.ts";
34// Discord API endpoints
36console.log(`Fetched ${messages.length} messages`);
37
38// Save messages to database
39await saveDMMessages(messages);
40
discord-botquery-service.ts1 match
1// Query service for Val.town
2import { getMessages, getLinks } from "./database.ts";
3import { analyzeConversation, summarizeConversation } from "./anthropic-service.ts";
4
discord-botdiscord-interactions.ts2 matches
2import { verifyKey } from "https://esm.sh/discord-interactions@3.4.0";
3import { processQuery } from "./query-service.ts";
4import { getCategories } from "./database.ts";
5import { createCommandResponse, getEnv, log, truncateText } from "../shared/utils.ts";
6import type {
117
118case 'categories': {
119// Get categories from database instead of hardcoding
120const categoriesFromDB = await getCategories();
121const categoryNames = categoriesFromDB.length > 0
1541551. Customize the bot's responses by editing the API endpoints in `api-server.js`
1562. Add more categories for link classification in `database.js`
1573. Enhance the AI queries by modifying prompts in `query-service.js`
1584. Create a web interface that connects to your API endpoints
discord-botdatabase.js15 matches
1import Database from 'better-sqlite3';
2import linkify from 'linkify-it';
3import 'dotenv/config';
45// For Val.town, we'll use the built-in SQLite functionality
6// In local dev, we'll use a file-based database
7const DB_PATH = process.env.NODE_ENV === 'production' ? ':memory:' : './messages.db';
81112/**
13* Initialize the database schema
14*/
15export function initializeDatabase() {
16const db = new Database(DB_PATH);
17
18// Create messages table
9798/**
99* Save messages to the database
100* @param {Array} messages - Array of message objects to save
101*/
102export async function saveDMMessages(messages) {
103const db = initializeDatabase();
104
105// Prepare statements
165transaction(messages);
166
167console.log(`Saved ${messages.length} messages to database`);
168
169db.close();
171172/**
173* Get messages from the database, with optional filtering
174* @param {Object} filters - Optional filters for messages
175* @returns {Array} - Array of message objects
176*/
177export function getMessages(filters = {}) {
178const db = initializeDatabase();
179
180let query = `
229230/**
231* Get links from the database, with optional filtering
232* @param {Object} filters - Optional filters for links
233* @returns {Array} - Array of link objects
234*/
235export function getLinks(filters = {}) {
236const db = initializeDatabase();
237
238let query = `
292*/
293export function updateLinkCategory(linkId, category) {
294const db = initializeDatabase();
295
296db.prepare('UPDATE links SET category = ? WHERE id = ?').run(category, linkId);
304*/
305export function getCategories() {
306const db = initializeDatabase();
307
308const categories = db.prepare('SELECT * FROM categories ORDER BY name').all();
318*/
319export function addCategory(name) {
320const db = initializeDatabase();
321
322db.prepare('INSERT OR IGNORE INTO categories (name, created_at) VALUES (?, ?)').run(name, Date.now());
vt-discordREADME.md1 match
9- The **client-side entrypoint** is `/frontend/index.html`, which in turn imports `/frontend/index.tsx`, which in turn imports the React app from `/frontend/components/App.tsx`.
1011[React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a fuller featured example project, with a SQLite database table, queries, client-side CSS and a favicon, and some shared code that runs on both client and server.
MiniAppStarterREADME.md1 match
9- The **client-side entrypoint** is `/frontend/index.html`, which in turn imports `/frontend/index.tsx`, which in turn imports the React app from `/frontend/App.tsx`.
1011[React Hono Example](https://www.val.town/x/stevekrouse/reactHonoExample) is a fuller featured example project, with a SQLite database table, queries, client-side CSS and a favicon, and some shared code that runs on both client and server.
MiniAppStarterApp.tsx5 matches
13const navLinks = [
14{ name: "Farcaster SDK", path: "/" },
15{ name: "Database", path: "/db" },
16{ name: "About", path: "/about" },
17];
35<Routes>
36<Route path="/" element={<FarcasterMiniApp />} />
37<Route path="/db" element={<Database />} />
38<Route path="/about" element={<About />} />
39<Route path="/neynar" element={<Neynar />} />
50<div className="">✷ Hono + React + Tailwind</div>
51<div className="">✷ React Router + React Query</div>
52<div className="">✷ Built-in database (blob storage)</div>
53<div className="">✷ Farcaster mini app manifest + webhook + embed metadata</div>
54<div className="">✷ Farcaster notifications (storing tokens, sending recurring notifications, ...)</div>
66}
6768function Database() {
69const queryFn = () => fetch("/api/counter/get").then((r) => r.json());
70const { data, refetch } = useQuery({ queryKey: ["counter"], queryFn });
71return (
72<Section className="flex flex-col items-start gap-3 m-5">
73{/* <h2 className="font-semibold">Database Example</h2> */}
74<div className="">Counter value: {data}</div>
75<Button variant="outline" onClick={() => fetch("/api/counter/increment").then(refetch)}>