From b8e1a33626b56b6d6ca1361c8dbf3d0071b76153 Mon Sep 17 00:00:00 2001 From: conrmahr Date: Wed, 5 Oct 2022 17:17:30 -0500 Subject: [PATCH 1/3] add option to post only feed, title, and url without embed --- README.md | 1 + src/listener/listener.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e2f6bbb..77640e4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ 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..915121d 100644 --- a/src/listener/listener.ts +++ b/src/listener/listener.ts @@ -92,6 +92,15 @@ function truncateString(str: string, to: number) { } async function executeHook(feed: Feed, embeds: DiscordEmbed[]) { + let content = ''; + let feedName = feed.name; + + if (process.env.SIMPLE) { + content = `**${feedName}**\n${embeds[0].title}\n${embeds[0].url}`; + embeds = []; + feedName = ''; + } + let result = await fetch(`${feed.hookUrl}?wait=true`, { method: "post", headers: { @@ -99,8 +108,9 @@ async function executeHook(feed: Feed, embeds: DiscordEmbed[]) { }, body: JSON.stringify({ allowed_mentions: [], + content: content, embeds: embeds, - username: feed.name, + username: feedName, }), }); if (result.status !== 200) { From 5e262fcc91d78344761b3d64fdd36aae48b92fd5 Mon Sep 17 00:00:00 2001 From: 3v Date: Mon, 10 Oct 2022 23:17:23 +0300 Subject: [PATCH 2/3] add railway deploy template --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 77640e4..e3235ba 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ 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: From 2ee5c9a49f99aae13588d9d76aa87be70f82955c Mon Sep 17 00:00:00 2001 From: conrmahr Date: Fri, 27 Jan 2023 12:06:53 -0600 Subject: [PATCH 3/3] fix: handle Discord API update on falsy fields --- src/listener/listener.ts | 50 ++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/src/listener/listener.ts b/src/listener/listener.ts index 915121d..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,30 +93,39 @@ function truncateString(str: string, to: number) { } async function executeHook(feed: Feed, embeds: DiscordEmbed[]) { - let content = ''; - let feedName = feed.name; + let username: any = feed.name; + let payload = { + allowed_mentions: [], + content: feed.name, + embeds: embeds, + username: username + }; if (process.env.SIMPLE) { - content = `**${feedName}**\n${embeds[0].title}\n${embeds[0].url}`; - embeds = []; - feedName = ''; + payload.content = `**${feed.name}**\n${embeds[0].title}\n${embeds[0].url}`; + payload.embeds = []; + delete payload['username']; } - let result = await fetch(`${feed.hookUrl}?wait=true`, { - method: "post", - headers: { - "content-type": "application/json", - }, - body: JSON.stringify({ - allowed_mentions: [], - content: content, - embeds: embeds, - username: feedName, - }), - }); - if (result.status !== 200) { - throw new Error(`${embeds[0].url}: ${result.status} ${result.statusText}`); - } + 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 {