mirror of
https://github.com/karl0ss/JDRssDownloader.git
synced 2025-04-27 20:03:40 +01:00
inital work on telegram notifications
This commit is contained in:
parent
393029ed37
commit
533bd23f6c
@ -3,6 +3,7 @@ const { linkAdder } = require('./JDLinkAdder');
|
|||||||
const { getLinksFromURL } = require('./LinkGrabber')
|
const { getLinksFromURL } = require('./LinkGrabber')
|
||||||
const { checkFileName } = require('./checkFileName')
|
const { checkFileName } = require('./checkFileName')
|
||||||
const { checkDownloadHistory } = require('./checkDownloadHistory')
|
const { checkDownloadHistory } = require('./checkDownloadHistory')
|
||||||
|
const { telegrambot } = require('./telegramCommunication')
|
||||||
|
|
||||||
async function filterFeed() {
|
async function filterFeed() {
|
||||||
let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows
|
let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows
|
||||||
@ -53,6 +54,9 @@ async function filterFeed() {
|
|||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
log.info(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.')
|
log.info(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.')
|
||||||
|
if (TelegramBotConfig) {
|
||||||
|
telegrambot(download_list.length + ' links for ' + urlObj.fileName + ' have been sent to JDdownloader.')
|
||||||
|
}
|
||||||
linkAdder(download_list)
|
linkAdder(download_list)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { feedUpdater } = require('./FeedUpdater')
|
const { feedUpdater } = require('./FeedUpdater')
|
||||||
const { filterFeed } = require('./FeedFilter')
|
const { filterFeed } = require('./FeedFilter')
|
||||||
|
const { telegrambot } = require('./telegramCommunication')
|
||||||
const version = require('./package.json').version;
|
const version = require('./package.json').version;
|
||||||
|
|
||||||
|
global.TelegramBotConfig = JSON.parse(fs.readFileSync('config.json')).TelegramBot
|
||||||
|
|
||||||
global.log = require('simple-node-logger').createSimpleLogger({
|
global.log = require('simple-node-logger').createSimpleLogger({
|
||||||
logFilePath: 'jdrssdownloader.log',
|
logFilePath: 'jdrssdownloader.log',
|
||||||
timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
|
timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
|
||||||
@ -10,6 +13,10 @@ global.log = require('simple-node-logger').createSimpleLogger({
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
log.info('Running JDRssDownloader version ' + version)
|
log.info('Running JDRssDownloader version ' + version)
|
||||||
|
|
||||||
|
if (TelegramBotConfig) {
|
||||||
|
telegrambot('Running JDRssDownloader version ' + version)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
RSSFeedRefreshMins = JSON.parse(fs.readFileSync('config.json')).RSSFeedRefreshMins
|
RSSFeedRefreshMins = JSON.parse(fs.readFileSync('config.json')).RSSFeedRefreshMins
|
||||||
JDPostLinksMins = JSON.parse(fs.readFileSync('config.json')).JDPostLinksMins
|
JDPostLinksMins = JSON.parse(fs.readFileSync('config.json')).JDPostLinksMins
|
||||||
@ -17,7 +24,13 @@ async function main() {
|
|||||||
log.error('config.json file is missing.')
|
log.error('config.json file is missing.')
|
||||||
}
|
}
|
||||||
log.info('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes')
|
log.info('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes')
|
||||||
|
if (TelegramBotConfig) {
|
||||||
|
telegrambot('Refreshing RSS Items every ' + RSSFeedRefreshMins + ' Minutes')
|
||||||
|
}
|
||||||
log.info('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes')
|
log.info('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes')
|
||||||
|
if (TelegramBotConfig) {
|
||||||
|
telegrambot('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes')
|
||||||
|
}
|
||||||
|
|
||||||
setInterval(await feedUpdater, RSSFeedRefreshMins * 60000);
|
setInterval(await feedUpdater, RSSFeedRefreshMins * 60000);
|
||||||
setInterval(await filterFeed, JDPostLinksMins * 60000);
|
setInterval(await filterFeed, JDPostLinksMins * 60000);
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
"JDPostLinksMins": 180,
|
"JDPostLinksMins": 180,
|
||||||
"Autostart": false,
|
"Autostart": false,
|
||||||
"OnlyHEVC": true,
|
"OnlyHEVC": true,
|
||||||
|
"TelegramBotID":"",
|
||||||
|
"TelegramChatID":123456789,
|
||||||
"Shows": [
|
"Shows": [
|
||||||
{
|
{
|
||||||
"Name": "",
|
"Name": "",
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"cheerio": "^1.0.0-rc.11",
|
"cheerio": "^1.0.0-rc.11",
|
||||||
"jdownloader-client": "^1.0.0",
|
"jdownloader-client": "^1.0.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
|
"node-telegram-bot-api": "^0.59.0",
|
||||||
"rss-parser": "^3.12.0",
|
"rss-parser": "^3.12.0",
|
||||||
"simple-node-logger": "^21.8.12"
|
"simple-node-logger": "^21.8.12"
|
||||||
},
|
},
|
||||||
|
20
telegramCommunication.js
Normal file
20
telegramCommunication.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const TelegramBot = require('node-telegram-bot-api');
|
||||||
|
const token = JSON.parse(fs.readFileSync('config.json')).TelegramBotID;
|
||||||
|
const chatId = JSON.parse(fs.readFileSync('config.json')).TelegramChatID;
|
||||||
|
|
||||||
|
const bot = new TelegramBot(token, { polling: false });
|
||||||
|
|
||||||
|
const telegrambot = (message) => {
|
||||||
|
try {
|
||||||
|
bot.sendMessage(chatId, message, {
|
||||||
|
parse_mode: 'html'
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Something went wrong when trying to send a Telegram notification', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
telegrambot
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user