Skip to content

Commit

Permalink
feat: parse rss feeds for our social platforms (#763)
Browse files Browse the repository at this point in the history
* feat: pull rss feeds for our socials

* fix: send open issues to socials channel

* fix: lint

* feat: load rss immediately on ready
  • Loading branch information
naomi-lgbt authored Jan 16, 2025
1 parent 9261d8a commit 091a9dc
Show file tree
Hide file tree
Showing 12 changed files with 491 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"node-schedule": "2.1.1",
"octokit": "4.1.0",
"prettier": "3.4.2",
"rss-parser": "3.13.0",
"string-similarity": "4.0.4",
"strip-ansi": "7.1.0",
"winston": "3.17.0"
Expand Down
36 changes: 36 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ model authors {
userId String @unique
hashnodeUsername String @unique
}

model rss {
id String @id @default(auto()) @map("_id") @db.ObjectId
blueskyId String @unique
redditId String @unique
forumId String @unique
hashnodeId String @unique
youtubeId String @unique
esYoutubeId String @unique
ptYoutubeId String @unique
}
2 changes: 2 additions & 0 deletions prod.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ PROD_DB="op://Environment Variables - freeCodeCamp/freeCodeCamp Live DB/database
PROD_COLLECTION="op://Environment Variables - freeCodeCamp/freeCodeCamp Live DB/collection"

TRANS_KEY="op://Environment Variables - freeCodeCamp/Camperchan Translation/credential"
TWITCH_CLIENT_ID="op://Environment Variables - freeCodeCamp/Camperchan Discord/twitch_id"
TWITCH_CLIENT_SECRET="op://Environment Variables - freeCodeCamp/Camperchan Discord/twitch_secret"
5 changes: 5 additions & 0 deletions src/config/youtubeIds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const youtubeIds = {
english: "UC8butISFwT-Wl7EV0hUK0BQ",
espanol: "UC1emV4A8liRs9p80CY8ElUQ",
portugues: "UCMh02FbsMgAZz_PDS6QjOKg",
};
7 changes: 7 additions & 0 deletions src/events/handlers/handleReady.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ChannelType } from "discord.js";
import { scheduleJob } from "node-schedule";
import { fetchRss } from "../../modules/fetchRss.js";
import { loadRoles } from "../../modules/loadRoles.js";
import { send100DaysOfCode } from "../../modules/send100DaysOfCode.js";
import { instantiateServer } from "../../server/serve.js";
Expand Down Expand Up @@ -73,6 +74,12 @@ export const handleReady = async(

await loadRoles(camperChan);

await fetchRss(camperChan);
setInterval(() => {
void fetchRss(camperChan);
// Every 30 minutes.
}, 1000 * 60 * 30);

scheduleJob("0 9 * * *", async() => {
await send100DaysOfCode(camperChan);
});
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ camperChan.quotes = await loadQuotes(camperChan);
camperChan.privateLogs = {};
camperChan.learnAccounts = {};
camperChan.translator = new Translator(process.env.TRANS_KEY ?? "");
camperChan.twitchCache = {};

await camperChan.login(camperChan.config.token);
3 changes: 2 additions & 1 deletion src/interfaces/extendedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ export interface ExtendedClient extends Client {
start: number;
end: number;
};
translator: Translator;
translator: Translator;
twitchCache: Record<string, string>;
}
100 changes: 100 additions & 0 deletions src/interfaces/rss.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* eslint-disable @typescript-eslint/naming-convention -- There are a lot of properties that we don't get to rename. */
interface BlueskyRss {
items: Array<{
link: string;
pubDate: string;
content: string;
contentSnippet: string;
guid: string;
isoDate: Date;
}>;
title: string;
description: string;
link: string;
}

interface RedditRss {
items: Array<{
title: string;
link: string;
pubDate: Date;
author: string;
content: string;
id: string;
isoDate: Date;
}>;
link: string;
feedUrl: string;
title: string;
lastBuildDate: Date;
}

interface NewsRss {
items: Array<{
"creator": string;
"title": string;
"link": string;
"pubDate": string;
"content:encoded": string;
"dc:creator": string;
"content": string;
"contentSnippet": string;
"guid": string;
"categories": Array<string>;
"isoDate": Date;
}>;
feedUrl: string;
image: {
link: string;
url: string;
title: string;
};
paginationLinks: {
self: string;
};
title: string;
description: string;
generator: string;
link: string;
lastBuildDate: string;
ttl: string;
}

interface YoutubeRss {
items: Array<{
title: string;
link: string;
pubDate: Date;
author: string;
id: string;
isoDate: Date;
}>;
link: string;
feedUrl: string;
title: string;
}

interface TwitchJson {
data: Array<{
id: string;
user_id: string;
user_login: string;
user_name: string;
game_id: string;
game_name: string;
type: string;
title: string;
viewer_count: number;
started_at: Date;
language: string;
thumbnail_url: string;
tag_ids: Array<unknown>;
tags: Array<string>;
is_mature: boolean;
}>;
pagination: {
cursor: string;
};
}

export type { BlueskyRss, RedditRss, NewsRss, YoutubeRss, TwitchJson };
Loading

0 comments on commit 091a9dc

Please sign in to comment.