Update dependencies and other stuff
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
1f5625877b
commit
536e75abba
@ -1,3 +0,0 @@
|
||||
{
|
||||
"url": "https://drone.hibas123.de/hibas123/THM_OSPLUS_NEWS_MAILER"
|
||||
}
|
@ -4,7 +4,7 @@ name: default
|
||||
|
||||
steps:
|
||||
- name: Build with node
|
||||
image: node:12
|
||||
image: node:19
|
||||
commands:
|
||||
- npm install
|
||||
- npm run build
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@ node_modules/
|
||||
logs/
|
||||
db.json
|
||||
lib/
|
||||
.yarn/cache
|
||||
.yarn/install-state.gz
|
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
Normal file
541
.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
873
.yarn/releases/yarn-3.5.0.cjs
vendored
Normal file
873
.yarn/releases/yarn-3.5.0.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
9
.yarnrc.yml
Normal file
9
.yarnrc.yml
Normal file
@ -0,0 +1,9 @@
|
||||
nodeLinker: node-modules
|
||||
|
||||
npmRegistryServer: "https://npm.hibas123.de"
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.5.0.cjs
|
@ -1,4 +1,4 @@
|
||||
FROM node:12
|
||||
FROM node:19
|
||||
|
||||
LABEL maintainer="Fabian Stamm <dev@fabianstamm.de>"
|
||||
|
||||
|
1509
package-lock.json
generated
1509
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
39
package.json
39
package.json
@ -5,31 +5,32 @@
|
||||
"author": "Fabian Stamm <dev@fabianstamm.de>",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node lib/index.js",
|
||||
"build": "tsc",
|
||||
"watch-ts": "tsc -w",
|
||||
"watch-js": "nodemon -i db.json lib/index.js",
|
||||
"watch": "concurrently npm:watch-*"
|
||||
"dev": "nodemon -e ts --exec 'node --loader ts-node/esm src/index.ts'"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/dotenv": "^8.2.0",
|
||||
"@types/html-entities": "^1.2.16",
|
||||
"@types/lowdb": "^1.0.5",
|
||||
"@types/node": "^13.1.4",
|
||||
"@types/node-fetch": "^2.5.4",
|
||||
"concurrently": "^5.0.2",
|
||||
"nodemon": "^2.0.2",
|
||||
"typescript": "^3.7.4"
|
||||
"@types/html-entities": "^1.3.4",
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/node-fetch": "^3.0.3",
|
||||
"nodemon": "^2.0.22",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hibas123/nodelogging": "^2.1.2",
|
||||
"dotenv": "^8.2.0",
|
||||
"html-entities": "^1.2.1",
|
||||
"lowdb": "^1.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"rss-parser": "^3.7.3",
|
||||
"ssl-root-cas": "^1.2.5",
|
||||
"telegraf": "^3.35.0"
|
||||
}
|
||||
"@hibas123/nodelogging": "^3.1.3",
|
||||
"@types/lodash": "^4.14.192",
|
||||
"dotenv": "^16.0.3",
|
||||
"html-entities": "^2.3.3",
|
||||
"lodash": "^4.17.21",
|
||||
"lowdb": "^5.1.0",
|
||||
"node-fetch": "^3.3.1",
|
||||
"rss-parser": "^3.13.0",
|
||||
"ssl-root-cas": "^1.3.1",
|
||||
"telegraf": "^4.12.2"
|
||||
},
|
||||
"packageManager": "yarn@3.5.0"
|
||||
}
|
81
src/index.ts
81
src/index.ts
@ -1,30 +1,44 @@
|
||||
require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
|
||||
require('ssl-root-cas').inject();
|
||||
// require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();
|
||||
// require('ssl-root-cas').inject();
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
|
||||
import Logging from "@hibas123/nodelogging";
|
||||
import { createHash } from "crypto";
|
||||
import * as dotenv from "dotenv";
|
||||
import { AllHtmlEntities } from "html-entities";
|
||||
import low from "lowdb";
|
||||
import FileSync from "lowdb/adapters/FileSync";
|
||||
import { decode } from "html-entities";
|
||||
|
||||
import fetch from "node-fetch";
|
||||
import rss from "rss-parser";
|
||||
import Telegraf from "telegraf";
|
||||
|
||||
import { Telegraf } from "telegraf";
|
||||
import { message } from "telegraf/filters";
|
||||
import * as fs from "fs";
|
||||
import lodash from 'lodash'
|
||||
|
||||
|
||||
Promise.resolve().then(async () => {
|
||||
const { Low, LowSync } = await import("lowdb");
|
||||
// @ts-ignore
|
||||
const { JSONFileSync } = await import("lowdb/node") as any;
|
||||
|
||||
class LowWithLodash<T> extends LowSync<T> {
|
||||
chain: lodash.ExpChain<this['data']> = lodash.chain(this).get('data')
|
||||
}
|
||||
|
||||
dotenv.config();
|
||||
const parser = new rss();
|
||||
const entities = new AllHtmlEntities();
|
||||
// const entities = new AllHtmlEntities();
|
||||
|
||||
if (!fs.existsSync("./persist")) {
|
||||
fs.mkdirSync("./persist")
|
||||
}
|
||||
|
||||
const adapter = new FileSync<{ feeds: IDBFeed[] }>("persist/db.json");
|
||||
const db = low(adapter);
|
||||
db.defaults({ feeds: [] }).write();
|
||||
// @ts-ignore
|
||||
const adapter = new JSONFileSync<{ feeds: IDBFeed[] }>("persist/db.json");
|
||||
const db: any = new LowWithLodash(adapter);
|
||||
db.read();
|
||||
|
||||
db.chain.defaults({ feeds: [] });
|
||||
db.write();
|
||||
|
||||
interface IDBFeed {
|
||||
url: string;
|
||||
@ -34,7 +48,7 @@ interface IDBFeed {
|
||||
|
||||
class Database {
|
||||
static findFeed(url: string): DBFeed {
|
||||
const feed = db.get("feeds").find(e => e.url === url).value();
|
||||
const feed = db.chain.get("feeds").find(e => e.url === url).value();
|
||||
return feed ? new DBFeed(feed) : undefined;
|
||||
}
|
||||
|
||||
@ -45,7 +59,8 @@ class Database {
|
||||
oldEntries: [],
|
||||
subscriber: []
|
||||
};
|
||||
db.get("feeds").unshift(feed).write();
|
||||
db.chain.get("feeds").unshift(feed)
|
||||
db.write();
|
||||
return feed;
|
||||
}
|
||||
|
||||
@ -58,23 +73,26 @@ class Database {
|
||||
return;
|
||||
}
|
||||
}
|
||||
db.get("feeds").find(e => e.url === url).get("subscriber").push(chatid).write();
|
||||
db.chain.get("feeds").find(e => e.url === url).get("subscriber").push(chatid)
|
||||
db.write();
|
||||
}
|
||||
|
||||
static findSubscribed(chatid: number) {
|
||||
return db.get("feeds").filter(e => e.subscriber.indexOf(chatid) >= 0).value();
|
||||
return db.chain.get("feeds").filter(e => e.subscriber.indexOf(chatid) >= 0).value();
|
||||
}
|
||||
|
||||
static removeSubscriber(url: string, chatid: number) {
|
||||
db.get("feeds").find(e => e.url === url).get("subscriber").remove(e => e === chatid).write();
|
||||
db.chain.get("feeds").find(e => e.url === url).get("subscriber").remove(e => e === chatid)
|
||||
db.write();
|
||||
}
|
||||
|
||||
static addItems(url: string, hashes: string[]) {
|
||||
db.get("feeds").find(e => e.url === url).get("oldEntries").unshift(...hashes).write();
|
||||
db.chain.get("feeds").find(e => e.url === url).get("oldEntries").unshift(...hashes)
|
||||
db.write();
|
||||
}
|
||||
|
||||
static getAll() {
|
||||
return db.get("feeds").map(feed => new DBFeed(feed)).value();
|
||||
return db.chain.get("feeds").map(feed => new DBFeed(feed)).value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +182,7 @@ bot.command("list", async (ctx) => {
|
||||
await ctx.reply("You are currently subscribed to: \n" + feeds);
|
||||
})
|
||||
|
||||
bot.on("message", async ctx => {
|
||||
bot.on(message("text", "entities"), async ctx => {
|
||||
const chatid = ctx.chat.id;
|
||||
Logging.debug("Message From:", chatid, ctx.message);
|
||||
|
||||
@ -178,9 +196,11 @@ bot.on("message", async ctx => {
|
||||
else
|
||||
Logging.error("Cannot find created feed!")
|
||||
}))
|
||||
if (urls.length === 0)
|
||||
await ctx.reply("No URLs found in message.");
|
||||
})
|
||||
|
||||
bot.startPolling();
|
||||
bot.launch()
|
||||
|
||||
async function sendFeedTelegraf(feed: DBFeed, items: IFeedItem[]) {
|
||||
Logging.debug("Before send", feed, items);
|
||||
@ -189,7 +209,7 @@ async function sendFeedTelegraf(feed: DBFeed, items: IFeedItem[]) {
|
||||
items.map(
|
||||
item => bot.telegram.sendMessage(
|
||||
subscriber,
|
||||
item.guid + "\n" + entities.decode(item.title) + "\n\n" + entities.decode(item.contentSnippet)
|
||||
item.guid + "\n" + decode(item.title) + "\n\n" + decode(item.contentSnippet)
|
||||
).catch(err => Logging.error(err)).then(() => Logging.debug("Message Sent"))
|
||||
)
|
||||
)
|
||||
@ -204,21 +224,4 @@ setInterval(() => {
|
||||
checkAll();
|
||||
}, 1000 * 60 * 60);
|
||||
checkAll();
|
||||
|
||||
// import { AllHtmlEntities } from "html-entities";
|
||||
// import { fstat } from "fs";
|
||||
// const entities = new AllHtmlEntities();
|
||||
// async function sendFeedMail(feed: Feed, item: IFeedItem) {
|
||||
// Logging.log("Sending Mail!")
|
||||
// let mailOptions = {
|
||||
// from: process.env.MAIL_SENDER,
|
||||
// to: process.env.MAIL_RECEIVER,
|
||||
// subject: '[OSPLUS_UPDATE] ' + entities.decode(item.title),
|
||||
// text: entities.decode(item.contentSnippet),
|
||||
// html: item.content
|
||||
// };
|
||||
|
||||
// let info = await transporter.sendMail(mailOptions);
|
||||
// Logging.log('Message sent: %s', info.messageId);
|
||||
// db.set(calculateHash(item), true).write();
|
||||
// }
|
||||
})
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "./lib",
|
||||
"strict": false,
|
||||
"esModuleInterop": true,
|
||||
"preserveWatchOutput": true
|
||||
"preserveWatchOutput": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"include": [
|
||||
"./src"
|
||||
]
|
||||
"include": ["./src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
Loading…
Reference in New Issue
Block a user