diff --git a/README.md b/README.md index e2f6bbb..e3235ba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/listener/listener.ts b/src/listener/listener.ts index e10dec6..8b36e5a 100644 --- a/src/listener/listener.ts +++ b/src/listener/listener.ts @@ -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"; @@ -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 {