Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/$%7Bart_info.art.src%7D?q=fetch&page=37&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=fetch

Returns an array of strings in format "username" or "username/projectName"

Found 8163 results for "fetch"(1474ms)

discord-botREADME.md4 matches

@boucher•Updated 4 days ago
10- **Furniture Focus**: Special features for tracking furniture links and discussions
11- **Val.town Integration**: Runs on Val.town for easy deployment and scheduling
12- **Periodic Updates**: Automatically fetches new messages on a schedule
13
14## Use Cases
58 ```
59
606. Test the DM fetching process
61 ```
62 node val-town-cron.js
84 - Add the same environment variables from your `.env` file
85
865. Set up a scheduled task on Val.town for periodic DM fetching
87 - Create a new scheduled task using the Val.town dashboard
88 - Use the `discordDMBotCron` function
108
109- `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

discord-bot.cursorrules3 matches

@boucher•Updated 4 days ago
239
240 // Inject data to avoid extra round-trips
241 const initialData = await fetchInitialData();
242 const dataScript = `<script>
243 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
286
2875. **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`
290
291

discord-botindex.js7 matches

@boucher•Updated 4 days ago
1import { initializeDatabase } from './database.js';
2import { fetchAndStoreDMs } from './discord-client.js';
3import { batchProcessLinks } from './link-analyzer.js';
4import express from 'express';
20});
21
22// Manual trigger for fetching DMs
23app.post('/api/fetch-dms', async (req, res) => {
24 try {
25 console.log('Manually triggering DM fetch...');
26 await fetchAndStoreDMs();
27 res.json({ success: true, message: 'DM fetch completed successfully' });
28 } catch (error) {
29 console.error('Error fetching DMs:', error);
30 res.status(500).json({ success: false, error: error.message });
31 }

discord-botlink-analyzer.js1 match

@boucher•Updated 4 days ago
119export async function extractLinkMetadata(url) {
120 try {
121 // In a production system, you'd want to actually fetch the page content
122 // For simplicity, we'll make an educated guess based on the URL
123

discord-botREADME.md4 matches

@boucher•Updated 4 days ago
15- **AI Integration**: Leverages Anthropic's Claude API for analysis
16- **Discord Integration**:
17 - Bot token for fetching messages
18 - Slash commands for user interactions
19 - Webhook endpoint for Discord interactions
502. Copy the contents of the backend directory
513. Set up the required environment variables
524. Create a cron schedule for periodically fetching messages and processing links
53
54## Usage
58- `GET /health`: Check if the service is running
59- `POST /api/interactions`: Discord interactions endpoint
60- `POST /api/fetch-dms`: Manually trigger DM fetching
61- `POST /api/process-links`: Manually trigger link processing
62- `POST /api/query`: Process a query about your messages
63- `POST /api/commands/search`: Endpoint for search commands
64- `POST /api/register-commands`: Register Discord slash commands
65- `GET /api/cron/fetch-dms`: Cron endpoint for fetching DMs
66- `GET /api/cron/process-links`: Cron endpoint for processing links
67

discord-botlink-analyzer.ts1 match

@boucher•Updated 4 days ago
142export async function extractLinkMetadata(url: string): Promise<MetadataResult> {
143 try {
144 // In a production system, you'd want to actually fetch the page content
145 // For simplicity, we'll make an educated guess based on the URL
146

discord-botindex.ts18 matches

@boucher•Updated 4 days ago
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";
7import { batchProcessLinks } from "./link-analyzer.ts";
85});
86
87// Manual trigger for fetching DMs
88app.post("/api/fetch-dms", async c => {
89 try {
90 log("Manually triggering DM fetch...", "info");
91 const messages = await fetchAndStoreDMs();
92 return c.json({
93 success: true,
94 message: "DM fetch completed successfully",
95 count: messages.length,
96 timestamp: new Date().toISOString()
97 });
98 } catch (error) {
99 log(`Error fetching DMs: ${error instanceof Error ? error.message : String(error)}`, "error");
100 return c.json({
101 success: false,
247
248/**
249 * Handles the scheduled DM fetch cron job
250 */
251export async function cronFetchDMs() {
252 try {
253 log("Running scheduled DM fetch...", "info");
254 await initializeServices(); // Ensure services are initialized
255 const messages = await fetchAndStoreDMs();
256
257 log(`Scheduled DM fetch completed successfully. Fetched ${messages.length} messages.`, "info");
258 return {
259 success: true,
260 message: "Scheduled DM fetch completed successfully",
261 count: messages.length,
262 timestamp: new Date().toISOString()
263 };
264 } catch (error) {
265 log(`Error in DM fetch cron job: ${error instanceof Error ? error.message : String(error)}`, "error");
266 return {
267 success: false,
297
298// Expose cron endpoints via HTTP as well
299app.get("/api/cron/fetch-dms", async c => {
300 const result = await cronFetchDMs();
301 return c.json(result, result.success ? 200 : 500);
302});
313});
314
315// Export the fetch handler for Val.town HTTP vals
316export default app.fetch;

discord-botdiscord-commands.ts1 match

@boucher•Updated 4 days ago
53
54 try {
55 const response = await fetch(endpoint, {
56 method: 'PUT',
57 headers: {

discord-botdiscord-client.ts27 matches

@boucher•Updated 4 days ago
6
7/**
8 * Handle fetching DMs between users using Discord's API
9 */
10export class DiscordClient {
16
17 /**
18 * Fetch DMs between the user and their partner
19 * @returns {Promise<Array>} - Array of message objects
20 */
21 async fetchDMsBetweenUsers() {
22 try {
23 const myUserId = Deno.env.get("DISCORD_USER_ID");
31 const dmChannel = await this.getDMChannel(spouseUserId);
32
33 // Fetch messages from the DM channel
34 const messages = await this.fetchMessagesFromChannel(dmChannel.id, myUserId, spouseUserId);
35
36 console.log(`Fetched ${messages.length} messages`);
37
38 // Save messages to database
41 return messages;
42 } catch (error) {
43 console.error("Error fetching DMs:", error);
44 throw error;
45 }
53 async getDMChannel(userId: string) {
54 try {
55 const response = await fetch(`${API_BASE}/users/@me/channels`, {
56 method: "POST",
57 headers: {
77
78 /**
79 * Fetch messages from a channel
80 * @param channelId - The channel ID to fetch messages from
81 * @param myUserId - The user's ID
82 * @param spouseUserId - The spouse's ID
83 * @returns - Array of message objects
84 */
85 async fetchMessagesFromChannel(channelId: string, myUserId: string, spouseUserId: string) {
86 const messages = [];
87 let lastId;
88 let keepFetching = true;
89
90 // Fetch messages in batches of 100 (Discord API limit)
91 while (keepFetching) {
92 let url = `${API_BASE}/channels/${channelId}/messages?limit=100`;
93 if (lastId) {
95 }
96
97 const response = await fetch(url, {
98 headers: {
99 "Authorization": `Bot ${this.token}`
103 if (!response.ok) {
104 const error = await response.text();
105 throw new Error(`Failed to fetch messages: ${error}`);
106 }
107
108 const fetchedMessages = await response.json();
109
110 if (fetchedMessages.length === 0) {
111 keepFetching = false;
112 break;
113 }
114
115 // Process and store fetched messages
116 for (const msg of fetchedMessages) {
117 // Only store messages from the two users we care about
118 if (msg.author.id === myUserId || msg.author.id === spouseUserId) {
129
130 // Get the ID of the last message for pagination
131 lastId = fetchedMessages[fetchedMessages.length - 1].id;
132
133 // If we got fewer messages than requested, we've reached the end
134 if (fetchedMessages.length < 100) {
135 keepFetching = false;
136 }
137 }
142
143/**
144 * Function to run the message fetching process
145 */
146export async function fetchAndStoreDMs() {
147 const token = Deno.env.get("DISCORD_TOKEN");
148 if (!token) {
151
152 const client = new DiscordClient(token);
153 return await client.fetchDMsBetweenUsers();
154}

discord-botval-town-deploy.js1 match

@boucher•Updated 4 days ago
23 name: 'discordDMBotCron',
24 isPublic: false,
25 description: 'Cron job to fetch Discord DMs periodically'
26 },
27 {

fetchPaginatedData2 file matches

@nbbaier•Updated 1 week ago

FetchBasic1 file match

@fredmoon•Updated 1 week ago