hn_job_analyzerhnService.ts30 matches
1export async function fetchHiringPosts(postId?: number): Promise<any[]> {
2try {
3// If no post ID is provided, find the latest "Who is hiring" post
6}
7
8// Fetch the post data
9const post = await fetchItem(postId);
10
11// Fetch all comments
12const comments = await Promise.all(
13(post.kids || []).map(async (commentId: number) => {
14return await fetchItem(commentId);
15})
16);
19return comments.filter(comment => !comment.deleted && !comment.dead);
20} catch (error) {
21console.error('Error fetching hiring posts:', error);
22throw error;
23}
24}
2526export async function fetchWantToBeHiredPosts(postId?: number): Promise<any[]> {
27try {
28// If no post ID is provided, find the latest "Who wants to be hired" post
31}
32
33// Fetch the post data
34const post = await fetchItem(postId);
35
36// Fetch all comments
37const comments = await Promise.all(
38(post.kids || []).map(async (commentId: number) => {
39return await fetchItem(commentId);
40})
41);
44return comments.filter(comment => !comment.deleted && !comment.dead);
45} catch (error) {
46console.error('Error fetching want to be hired posts:', error);
47throw error;
48}
49}
5051export async function fetchFreelancerPosts(postId?: number): Promise<any[]> {
52try {
53// If no post ID is provided, find the latest "Freelancer? Seeking Freelancer?" post
56}
57
58// Fetch the post data
59const post = await fetchItem(postId);
60
61// Fetch all comments
62const comments = await Promise.all(
63(post.kids || []).map(async (commentId: number) => {
64return await fetchItem(commentId);
65})
66);
69return comments.filter(comment => !comment.deleted && !comment.dead);
70} catch (error) {
71console.error('Error fetching freelancer posts:', error);
72throw error;
73}
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`);
79return await response.json();
80}
84try {
85// First, get the latest stories
86const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
87const storyIds = await response.json();
88
89// Fetch the latest 50 stories to find the most recent "Who is hiring" post
90const stories = await Promise.all(
91storyIds.slice(0, 50).map(async (id: number) => {
92return await fetchItem(id);
93})
94);
116try {
117// First, get the latest stories
118const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
119const storyIds = await response.json();
120
121// Fetch the latest 50 stories to find the most recent "Who wants to be hired" post
122const stories = await Promise.all(
123storyIds.slice(0, 50).map(async (id: number) => {
124return await fetchItem(id);
125})
126);
148try {
149// First, get the latest stories
150const response = await fetch('https://hacker-news.firebaseio.com/v0/askstories.json');
151const storyIds = await response.json();
152
153// Fetch the latest 50 stories to find the most recent "Freelancer? Seeking Freelancer?" post
154const stories = await Promise.all(
155storyIds.slice(0, 50).map(async (id: number) => {
156return await fetchItem(id);
157})
158);
discord-botapi-server.js3 matches
73res.json({ success: true, data: messages });
74} catch (error) {
75console.error('Error fetching messages:', error);
76res.status(500).json({ success: false, error: error.message });
77}
92res.json({ success: true, data: links });
93} catch (error) {
94console.error('Error fetching links:', error);
95res.status(500).json({ success: false, error: error.message });
96}
103res.json({ success: true, data: categories });
104} catch (error) {
105console.error('Error fetching categories:', error);
106res.status(500).json({ success: false, error: error.message });
107}
discord-botval-town-cron.js4 matches
1import { fetchAndStoreDMs } from './discord-client.js';
2import 'dotenv/config';
311*/
12export default async function cronHandler() {
13console.log('Starting scheduled Discord DM fetch...');
14try {
15await fetchAndStoreDMs();
16return { success: true, message: 'Successfully fetched and stored DMs' };
17} catch (error) {
18console.error('Error in cron job:', error);
discord-botdiscord-client.js22 matches
45/**
6* Discord client that fetches direct messages between users
7*/
8export class DiscordClient {
2829/**
30* Fetch DMs between the user and their spouse
31* @returns {Promise<Array>} - Array of message objects
32*/
33async fetchDMsBetweenUsers() {
34try {
35const myUserId = process.env.DISCORD_USER_ID;
4142// Get the DM channel with spouse
43const spouse = await this.client.users.fetch(spouseUserId);
44const dmChannel = await spouse.createDM();
45
46// Fetch messages from the DM channel
47const messages = [];
48let lastId;
49let keepFetching = true;
50
51// Fetch messages in batches of 100 (Discord API limit)
52while (keepFetching) {
53const options = { limit: 100 };
54if (lastId) {
56}
57
58const fetchedMessages = await dmChannel.messages.fetch(options);
59
60if (fetchedMessages.size === 0) {
61keepFetching = false;
62break;
63}
64
65// Process and store fetched messages
66fetchedMessages.forEach(msg => {
67// Only store messages from the two users we care about
68if (msg.author.id === myUserId || msg.author.id === spouseUserId) {
79
80// Get the ID of the last message for pagination
81lastId = fetchedMessages.last().id;
82
83// If we got fewer messages than requested, we've reached the end
84if (fetchedMessages.size < 100) {
85keepFetching = false;
86}
87}
88
89console.log(`Fetched ${messages.length} messages`);
90
91// Save messages to database
94return messages;
95} catch (error) {
96console.error('Error fetching DMs:', error);
97throw error;
98}
108109/**
110* Function to run the message fetching process
111*/
112export async function fetchAndStoreDMs() {
113const client = new DiscordClient();
114try {
115await client.login();
116await client.fetchDMsBetweenUsers();
117} catch (error) {
118console.error('Error in fetch and store process:', error);
119} finally {
120client.disconnect();
discord-botinteractions-endpoint.js2 matches
140});
141} catch (error) {
142console.error('Error fetching categories:', error);
143return res.json({
144type: 4,
145data: { content: 'Sorry, I encountered an error fetching categories.' }
146});
147}
discord-botpackage.json1 match
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
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
1314## Use Cases
58```
59606. Test the DM fetching process
61```
62node val-town-cron.js
84- Add the same environment variables from your `.env` file
85865. 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
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
discord-bot.cursorrules3 matches
239
240// Inject data to avoid extra round-trips
241const initialData = await fetchInitialData();
242const dataScript = `<script>
243window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
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`
290291
discord-botindex.js7 matches
1import { initializeDatabase } from './database.js';
2import { fetchAndStoreDMs } from './discord-client.js';
3import { batchProcessLinks } from './link-analyzer.js';
4import express from 'express';
20});
2122// Manual trigger for fetching DMs
23app.post('/api/fetch-dms', async (req, res) => {
24try {
25console.log('Manually triggering DM fetch...');
26await fetchAndStoreDMs();
27res.json({ success: true, message: 'DM fetch completed successfully' });
28} catch (error) {
29console.error('Error fetching DMs:', error);
30res.status(500).json({ success: false, error: error.message });
31}
discord-botlink-analyzer.js1 match
119export async function extractLinkMetadata(url) {
120try {
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