8}
910export function WelcomeMessage({ user, onLeave }: WelcomeMessageProps) {
11return (
12<div className="usps-card flex flex-row justify-between">
reddit-checkerREADME.md4 matches
76```
7778#### Test Full Functionality โ VERIFIED (Multi-subreddit support added)
79```
80GET /test-reddit-api.ts?action=test&client_id=151sZ8h5TaHVZGZZn0rOhA&subreddit=lovable
170### Adjusting Post Limit
171172Modify the `limit` parameter in the `fetchSubredditPosts` function call:
173174```typescript
187188- โ Reddit API authentication working
189- โ Post fetching functional across multiple subreddits
190- โ Keyword matching operational
191- โ Slack notifications configured and tested
235## ๐ Backup Options
236237The project includes an RSS-based monitor (`reddit-rss-monitor.ts`) as a backup option if the API approach encounters issues. The RSS monitor has similar functionality but uses Reddit's RSS feeds instead of the official API.
reddit-checkerreddit-api-monitor.ts9 matches
74* Gets an access token from Reddit API
75*/
76async function getRedditAccessToken(): Promise<string> {
77try {
78// Check if we have a cached token
117* Fetches recent posts from a subreddit using Reddit API
118*/
119async function fetchSubredditPosts(subreddit: string, limit: number = 25): Promise<RedditPost[]> {
120try {
121const accessToken = await getRedditAccessToken();
144* Checks if a post contains any of the specified keywords
145*/
146function containsKeywords(post: RedditPost, keywords: string[]): boolean {
147const searchText = `${post.title} ${post.selftext}`.toLowerCase();
148return keywords.some(keyword => searchText.includes(keyword.toLowerCase()));
152* Formats a post for Slack notification
153*/
154function formatPostForSlack(post: RedditPost, matchedKeywords: string[]): any {
155const redditUrl = `https://www.reddit.com${post.permalink}`;
156const createdDate = new Date(post.created_utc * 1000).toLocaleString();
196* Sends notification to Slack
197*/
198async function sendSlackNotification(matchingPosts: Array<{ post: RedditPost; keywords: string[] }>): Promise<void> {
199const attachments = matchingPosts.map(({ post, keywords }) =>
200formatPostForSlack(post, keywords)
228* Gets the last checked timestamp from storage
229*/
230async function getLastChecked(): Promise<number> {
231try {
232const data = await blob.getJSON("reddit_api_monitor_last_checked");
240* Saves the last checked timestamp to storage
241*/
242async function saveLastChecked(timestamp: number): Promise<void> {
243await blob.setJSON("reddit_api_monitor_last_checked", { timestamp });
244}
245246/**
247* Main monitoring function
248*/
249export default async function() {
250console.log(`๐ Starting Reddit API monitor for ${CONFIG.subreddits.length} subreddits`);
251console.log(`๐ Subreddits: ${CONFIG.subreddits.map(s => `r/${s}`).join(', ')}`);
reddit-checkertest-slack.ts2 matches
21* Formats a post for Slack notification
22*/
23function formatPostForSlack(post: RedditPost, matchedKeywords: string[]): any {
24const redditUrl = `https://www.reddit.com${post.permalink}`;
25const createdDate = new Date(post.created_utc * 1000).toLocaleString();
65* Test Slack webhook
66*/
67export default async function(req: Request) {
68const url = new URL(req.url);
69const action = url.searchParams.get('action') || 'simple';
reddit-checkerconfig-manager.ts3 matches
37* Get current configuration
38*/
39async function getConfig(): Promise<ConfigData> {
40try {
41const data = await blob.getJSON("reddit_monitor_config");
55* Save configuration
56*/
57async function saveConfig(configData: ConfigData): Promise<void> {
58configData.lastUpdated = new Date().toISOString();
59await blob.setJSON("reddit_monitor_config", configData);
63* Configuration management API
64*/
65export default async function(req: Request) {
66const url = new URL(req.url);
67const action = url.searchParams.get('action') || 'list';
reddit-checkertest-reddit-api.ts4 matches
38* Gets an access token from Reddit API
39*/
40async function getRedditAccessToken(clientId: string, clientSecret: string): Promise<string> {
41try {
42const auth = btoa(`${clientId}:${clientSecret}`);
68* Fetches recent posts from a subreddit using Reddit API
69*/
70async function fetchSubredditPosts(accessToken: string, subreddit: string, limit: number = 10): Promise<RedditPost[]> {
71try {
72const url = `https://oauth.reddit.com/r/${subreddit}/new?limit=${limit}`;
95* Test the Reddit API connection
96*/
97export default async function(req: Request) {
98const url = new URL(req.url);
99const action = url.searchParams.get('action') || 'help';
156}
157
158// Test full functionality
159console.log(`๐ Testing Reddit API connection for r/${subreddit}...`);
160const accessToken = await getRedditAccessToken(clientId, clientSecret);
reddit-checkertest-main-monitor.ts2 matches
3*/
45// Import the main monitor function
6import monitor from "./reddit-api-monitor.ts";
78export default async function(req: Request) {
9const url = new URL(req.url);
10const action = url.searchParams.get('action') || 'run';
reddit-checkertest-rss-monitor.ts5 matches
1/**
2* Test script for Reddit RSS Monitor
3* This allows manual testing of the Reddit RSS monitoring functionality
4*/
518* Parses RSS/Atom XML and extracts items
19*/
20function parseRSS(xmlText: string): RSSItem[] {
21const items: RSSItem[] = [];
22
95* Fetches RSS feed from a subreddit
96*/
97async function fetchSubredditRSS(subreddit: string): Promise<RSSItem[]> {
98try {
99const url = `https://www.reddit.com/r/${subreddit}/new.rss`;
122* Converts RSS pubDate to timestamp
123*/
124function parseRSSDate(pubDate: string): number {
125try {
126return Math.floor(new Date(pubDate).getTime() / 1000);
133* Test the Reddit RSS connection and keyword matching
134*/
135export default async function(req: Request) {
136const url = new URL(req.url);
137const action = url.searchParams.get('action') || 'test';
reddit-checkerreddit-rss-monitor.ts9 matches
31* Parses RSS/Atom XML and extracts items
32*/
33function parseRSS(xmlText: string): RSSItem[] {
34const items: RSSItem[] = [];
35
108* Fetches RSS feed from a subreddit
109*/
110async function fetchSubredditRSS(subreddit: string): Promise<RSSItem[]> {
111try {
112const url = `https://www.reddit.com/r/${subreddit}/new.rss`;
135* Checks if an RSS item contains any of the specified keywords
136*/
137function containsKeywords(item: RSSItem, keywords: string[]): boolean {
138const searchText = `${item.title} ${item.description}`.toLowerCase();
139return keywords.some(keyword => searchText.includes(keyword.toLowerCase()));
143* Converts RSS pubDate to timestamp
144*/
145function parseRSSDate(pubDate: string): number {
146try {
147return Math.floor(new Date(pubDate).getTime() / 1000);
154* Formats an RSS item for notification
155*/
156function formatRSSItem(item: RSSItem, matchedKeywords: string[]): string {
157const pubDate = new Date(item.pubDate).toLocaleString();
158
184* Gets the last checked timestamp from storage
185*/
186async function getLastChecked(): Promise<number> {
187try {
188const data = await blob.getJSON("reddit_rss_monitor_last_checked");
196* Saves the last checked timestamp to storage
197*/
198async function saveLastChecked(timestamp: number): Promise<void> {
199await blob.setJSON("reddit_rss_monitor_last_checked", { timestamp });
200}
201202/**
203* Main monitoring function
204*/
205export default async function() {
206console.log(`๐ Starting Reddit RSS monitor for r/${CONFIG.subreddit}`);
207console.log(`๐ Keywords: ${CONFIG.keywords.join(', ')}`);
reddit-checkertest-reddit-monitor.ts3 matches
1/**
2* Test script for Reddit Monitor
3* This allows manual testing of the Reddit monitoring functionality
4*/
529* Fetches recent posts from a subreddit
30*/
31async function fetchSubredditPosts(subreddit: string, limit: number = 10): Promise<RedditPost[]> {
32try {
33const url = `https://www.reddit.com/r/${subreddit}/new.json?limit=${limit}`;
57* Test the Reddit API connection and keyword matching
58*/
59export default async function(req: Request) {
60const url = new URL(req.url);
61const action = url.searchParams.get('action') || 'test';