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=77&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 8567 results for "fetch"(958ms)

hn_job_analyzerhnService.ts30 matches

@prashamtrivedi•Updated 1 week ago
1export async function fetchHiringPosts(postId?: number): Promise<any[]> {
2 try {
3 // If no post ID is provided, find the latest "Who is hiring" post
6 }
7
8 // Fetch the post data
9 const post = await fetchItem(postId);
10
11 // Fetch all comments
12 const comments = await Promise.all(
13 (post.kids || []).map(async (commentId: number) => {
14 return await fetchItem(commentId);
15 })
16 );
19 return comments.filter(comment => !comment.deleted && !comment.dead);
20 } catch (error) {
21 console.error('Error fetching hiring posts:', error);
22 throw error;
23 }
24}
25
26export async function fetchWantToBeHiredPosts(postId?: number): Promise<any[]> {
27 try {
28 // If no post ID is provided, find the latest "Who wants to be hired" post
31 }
32
33 // Fetch the post data
34 const post = await fetchItem(postId);
35
36 // Fetch all comments
37 const comments = await Promise.all(
38 (post.kids || []).map(async (commentId: number) => {
39 return await fetchItem(commentId);
40 })
41 );
44 return comments.filter(comment => !comment.deleted && !comment.dead);
45 } catch (error) {
46 console.error('Error fetching want to be hired posts:', error);
47 throw error;
48 }
49}
50
51export async function fetchFreelancerPosts(postId?: number): Promise<any[]> {
52 try {
53 // If no post ID is provided, find the latest "Freelancer? Seeking Freelancer?" post
56 }
57
58 // Fetch the post data
59 const post = await fetchItem(postId);
60
61 // Fetch all comments
62 const comments = await Promise.all(
63 (post.kids || []).map(async (commentId: number) => {
64 return await fetchItem(commentId);
65 })
66 );
69 return comments.filter(comment => !comment.deleted && !comment.dead);
70 } catch (error) {
71 console.error('Error fetching freelancer posts:', error);
72 throw error;
73 }
74}
75
76// Helper function to fetch an item from the HN API
77async function fetchItem(id: number): Promise<any> {
78 const response = await fetch(`https://hacker-news.firebaseio.com/v0/item/${id}.json`);
79 return await response.json();
80}
84 try {
85 // First, get the latest stories
86 const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
87 const storyIds = await response.json();
88
89 // Fetch the latest 50 stories to find the most recent "Who is hiring" post
90 const stories = await Promise.all(
91 storyIds.slice(0, 50).map(async (id: number) => {
92 return await fetchItem(id);
93 })
94 );
116 try {
117 // First, get the latest stories
118 const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
119 const storyIds = await response.json();
120
121 // Fetch the latest 50 stories to find the most recent "Who wants to be hired" post
122 const stories = await Promise.all(
123 storyIds.slice(0, 50).map(async (id: number) => {
124 return await fetchItem(id);
125 })
126 );
148 try {
149 // First, get the latest stories
150 const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
151 const storyIds = await response.json();
152
153 // Fetch the latest 50 stories to find the most recent "Freelancer? Seeking Freelancer?" post
154 const stories = await Promise.all(
155 storyIds.slice(0, 50).map(async (id: number) => {
156 return await fetchItem(id);
157 })
158 );

discord-botapi-server.js3 matches

@boucher•Updated 1 week ago
73 res.json({ success: true, data: messages });
74 } catch (error) {
75 console.error('Error fetching messages:', error);
76 res.status(500).json({ success: false, error: error.message });
77 }
92 res.json({ success: true, data: links });
93 } catch (error) {
94 console.error('Error fetching links:', error);
95 res.status(500).json({ success: false, error: error.message });
96 }
103 res.json({ success: true, data: categories });
104 } catch (error) {
105 console.error('Error fetching categories:', error);
106 res.status(500).json({ success: false, error: error.message });
107 }

discord-botval-town-cron.js4 matches

@boucher•Updated 1 week ago
1import { fetchAndStoreDMs } from './discord-client.js';
2import 'dotenv/config';
3
11 */
12export default async function cronHandler() {
13 console.log('Starting scheduled Discord DM fetch...');
14 try {
15 await fetchAndStoreDMs();
16 return { success: true, message: 'Successfully fetched and stored DMs' };
17 } catch (error) {
18 console.error('Error in cron job:', error);

discord-botdiscord-client.js22 matches

@boucher•Updated 1 week ago
4
5/**
6 * Discord client that fetches direct messages between users
7 */
8export class DiscordClient {
28
29 /**
30 * Fetch DMs between the user and their spouse
31 * @returns {Promise<Array>} - Array of message objects
32 */
33 async fetchDMsBetweenUsers() {
34 try {
35 const myUserId = process.env.DISCORD_USER_ID;
41
42 // Get the DM channel with spouse
43 const spouse = await this.client.users.fetch(spouseUserId);
44 const dmChannel = await spouse.createDM();
45
46 // Fetch messages from the DM channel
47 const messages = [];
48 let lastId;
49 let keepFetching = true;
50
51 // Fetch messages in batches of 100 (Discord API limit)
52 while (keepFetching) {
53 const options = { limit: 100 };
54 if (lastId) {
56 }
57
58 const fetchedMessages = await dmChannel.messages.fetch(options);
59
60 if (fetchedMessages.size === 0) {
61 keepFetching = false;
62 break;
63 }
64
65 // Process and store fetched messages
66 fetchedMessages.forEach(msg => {
67 // Only store messages from the two users we care about
68 if (msg.author.id === myUserId || msg.author.id === spouseUserId) {
79
80 // Get the ID of the last message for pagination
81 lastId = fetchedMessages.last().id;
82
83 // If we got fewer messages than requested, we've reached the end
84 if (fetchedMessages.size < 100) {
85 keepFetching = false;
86 }
87 }
88
89 console.log(`Fetched ${messages.length} messages`);
90
91 // Save messages to database
94 return messages;
95 } catch (error) {
96 console.error('Error fetching DMs:', error);
97 throw error;
98 }
108
109/**
110 * Function to run the message fetching process
111 */
112export async function fetchAndStoreDMs() {
113 const client = new DiscordClient();
114 try {
115 await client.login();
116 await client.fetchDMsBetweenUsers();
117 } catch (error) {
118 console.error('Error in fetch and store process:', error);
119 } finally {
120 client.disconnect();

discord-botinteractions-endpoint.js2 matches

@boucher•Updated 1 week ago
140 });
141 } catch (error) {
142 console.error('Error fetching categories:', error);
143 return res.json({
144 type: 4,
145 data: { content: 'Sorry, I encountered an error fetching categories.' }
146 });
147 }

discord-botpackage.json1 match

@boucher•Updated 1 week ago
8 "start": "node index.js",
9 "dev": "node index.js",
10 "fetch": "node val-town-cron.js",
11 "register": "node discord-commands.js",
12 "interactions": "node interactions-endpoint.js",

discord-botREADME.md4 matches

@boucher•Updated 1 week 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 1 week 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 1 week 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 1 week 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

fetchPaginatedData2 file matches

@nbbaier•Updated 2 weeks ago

FetchBasic1 file match

@fredmoon•Updated 2 weeks ago