Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ Install node 18+ and npm, and run `npm install`, `npm run sync`.
For the web interface run `npm run build` and `npm start`.
For the RSS poller run `npm run build:runner` and `npm run runner`.

### Railway

[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/2LnViG?referralCode=6hr3nf)

### Configuration

The service can be configured using environment variables:

- `PORT` (default 3000) port to listen on
- `INTERVAL` (default 5) minutes between checks
- `SIMPLE` (default false) post feed, title, and url text only
- `REDIS_URL` (required) redis connect url
- `DISCORD_CLIENT_ID` (required) https://discord.com/developers/applications
- `DISCORD_CLIENT_SECRET` (required) https://discord.com/developers/applications
Expand Down
46 changes: 33 additions & 13 deletions src/listener/listener.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RequestQuote16 } from "carbon-icons-svelte";
import fetch from "node-fetch";
import Parser from "rss-parser";
import { DBName, Processing } from "../const.js";
Expand Down Expand Up @@ -92,20 +93,39 @@ function truncateString(str: string, to: number) {
}

async function executeHook(feed: Feed, embeds: DiscordEmbed[]) {
let result = await fetch(`${feed.hookUrl}?wait=true`, {
method: "post",
headers: {
"content-type": "application/json",
},
body: JSON.stringify({
allowed_mentions: [],
embeds: embeds,
username: feed.name,
}),
});
if (result.status !== 200) {
throw new Error(`${embeds[0].url}: ${result.status} ${result.statusText}`);
let username: any = feed.name;
let payload = {
allowed_mentions: [],
content: feed.name,
embeds: embeds,
username: username
};

if (process.env.SIMPLE) {
payload.content = `**${feed.name}**\n${embeds[0].title}\n${embeds[0].url}`;
payload.embeds = [];
delete payload['username'];
}

async function response(url = '', data = {}) {
const response = await fetch(url, {
method: 'POST',
headers: {
"Content-type": "application/json;"
},
body: JSON.stringify(data)
});

return response.json();
}

response(`${feed.hookUrl}?wait=true`, payload )
.then(json => {
console.log(json) // Handle success
})
.catch(err => {
console.log(err) // Handle errors
});
}

function getColor(content: string | undefined): number {
Expand Down