hn_job_analyzerhnService.ts1 match
74}
7576// Helper function to fetch an item from the HN API
77async function fetchItem(id: number): Promise<any> {
78const response = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
hn_job_analyzeraiAnalyzer.ts1 match
34// Initialize the Google Gemini model
5const GEMINI_API_KEY = Deno.env.get('GEMINI_API_KEY') || '';
6const model = google('gemini-2.5-flash', {
7structuredOutputs: true,
discord-botapi-server.js10 matches
1import express from 'express';
2import { getMessages, getLinks, getCategories, updateLinkCategory } from './database.js';
3import { Configuration, OpenAIApi } from 'openai';
4import 'dotenv/config';
510// Initialize OpenAI for AI-powered queries
11const configuration = new Configuration({
12apiKey: process.env.OPENAI_API_KEY,
13});
14const openai = new OpenAIApi(configuration);
1516/**
37`;
38
39// Call OpenAI API
40const response = await openai.createCompletion({
41model: "gpt-3.5-turbo-instruct",
52}
5354// API routes
5556// Health check endpoint
6061// Get messages with optional filters
62app.get('/api/messages', (req, res) => {
63try {
64const filters = {
7980// Get links with optional filters
81app.get('/api/links', (req, res) => {
82try {
83const filters = {
9899// Get all categories
100app.get('/api/categories', (req, res) => {
101try {
102const categories = getCategories();
109110// Update link category
111app.put('/api/links/:id/category', (req, res) => {
112try {
113const { id } = req.params;
127128// AI-powered query endpoint
129app.post('/api/query', async (req, res) => {
130try {
131const { query, filters } = req.body;
4// Initialize Anthropic client
5const anthropic = new Anthropic({
6apiKey: process.env.ANTHROPIC_API_KEY,
7});
8
discord-botdiscord-client.js1 match
49let keepFetching = true;
50
51// Fetch messages in batches of 100 (Discord API limit)
52while (keepFetching) {
53const options = { limit: 100 };
2829// Discord interaction endpoint
30app.post('/api/interactions', async (req, res) => {
31const { type, data } = req.body;
32
discord-bot.env.example3 matches
1# Discord API credentials
2DISCORD_TOKEN=your_discord_token_here
3DISCORD_CLIENT_ID=your_client_id_here
5SPOUSE_USER_ID=spouse_user_id_here
67# OpenAI API key (for AI-powered querying)
8OPENAI_API_KEY=your_openai_api_key_here
910# Val.town settings
discord-botREADME.md8 matches
25- Node.js 16+ and npm
26- Discord account with Bot token
27- OpenAI API key (for AI-powered queries)
28- Val.town account (for deployment)
2951- `DISCORD_USER_ID`: Your Discord user ID
52- `SPOUSE_USER_ID`: Your partner's Discord user ID
53- `OPENAI_API_KEY`: Your OpenAI API key
54555. Initialize the database
1037. Start a DM with your partner to create the DM channel the bot will monitor
104105## API Endpoints
106107The application exposes the following HTTP endpoints:
108109- `GET /health`: Health check endpoint
110- `POST /api/fetch-dms`: Manually trigger DM fetching
111- `POST /api/process-links`: Manually trigger link processing
112- `POST /api/query`: Submit a query about your message history
113- Body: `{ "query": "your question here", "filters": { optional filters } }`
114- `POST /api/commands/search`: Discord command endpoint for searching
115- Body: `{ "query": "your search term" }`
116145## Acknowledgements
146147- Discord.js for Discord API integration
148- OpenAI for AI-powered querying
149- Val.town for hosting and scheduling
discord-bot.cursorrules10 matches
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
2425- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
173However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
174If you need access to this data on the client, run it in the server and pass it to the client by splicing it into the HTML page
175or by making an API request for it.
176177## Val Town Platform Specifics
181- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
182- **Storage:** DO NOT use the Deno KV module for storage
183- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
184- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
185- **View Source:** Add a view source link by importing & using `import.meta.url.replace("ems.sh", "val.town)"` (or passing this data to the client) and include `target="_top"` attribute
186- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
187- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
188- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
189- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
190- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
224### Backend (Hono) Best Practices
225226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
248});
249```
250- Create RESTful API routes for CRUD operations
251- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
252```ts
285- For files in the project, use `readFile` helpers
2862875. **API Design:**
288- `fetch` handler is the entry point for HTTP vals
289- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
discord-botindex.js5 matches
13initializeDatabase();
1415// API routes
1617// Health check endpoint
2122// Manual trigger for fetching DMs
23app.post('/api/fetch-dms', async (req, res) => {
24try {
25console.log('Manually triggering DM fetch...');
3334// Manual trigger for processing links
35app.post('/api/process-links', async (req, res) => {
36try {
37console.log('Manually triggering link processing...');
4546// Query endpoint
47app.post('/api/query', async (req, res) => {
48try {
49const { query, filters } = req.body;
6263// Discord command endpoints
64app.post('/api/commands/search', async (req, res) => {
65try {
66const { query } = req.body;