mirror of
				https://github.com/karl0ss/JDRssDownloader.git
				synced 2025-11-04 00:21:00 +00:00 
			
		
		
		
	Merge pull request #6 from karl0ss/sendTelegram
inital work on telegram notifications
This commit is contained in:
		
						commit
						513986aad5
					
				@ -3,6 +3,7 @@ const { linkAdder } = require('./JDLinkAdder');
 | 
			
		||||
const { getLinksFromURL } = require('./LinkGrabber')
 | 
			
		||||
const { checkFileName } = require('./checkFileName')
 | 
			
		||||
const { checkDownloadHistory } = require('./checkDownloadHistory')
 | 
			
		||||
const { telegrambot } = require('./telegramCommunication')
 | 
			
		||||
 | 
			
		||||
async function filterFeed() {
 | 
			
		||||
    let myshowlist = JSON.parse(fs.readFileSync('config.json')).Shows
 | 
			
		||||
@ -53,6 +54,9 @@ async function filterFeed() {
 | 
			
		||||
                            break
 | 
			
		||||
                        } else {
 | 
			
		||||
                            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)
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,11 @@
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const { feedUpdater } = require('./FeedUpdater')
 | 
			
		||||
const { filterFeed } = require('./FeedFilter')
 | 
			
		||||
const { telegrambot } = require('./telegramCommunication')
 | 
			
		||||
const version = require('./package.json').version;
 | 
			
		||||
 | 
			
		||||
global.TelegramBotConfig = JSON.parse(fs.readFileSync('config.json')).TelegramBot
 | 
			
		||||
 | 
			
		||||
global.log = require('simple-node-logger').createSimpleLogger({
 | 
			
		||||
    logFilePath: 'jdrssdownloader.log',
 | 
			
		||||
    timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
 | 
			
		||||
@ -10,6 +13,10 @@ global.log = require('simple-node-logger').createSimpleLogger({
 | 
			
		||||
 | 
			
		||||
async function main() {
 | 
			
		||||
    log.info('Running JDRssDownloader version ' + version)
 | 
			
		||||
 | 
			
		||||
    if (TelegramBotConfig) {
 | 
			
		||||
        telegrambot('Running JDRssDownloader version ' + version)
 | 
			
		||||
    }
 | 
			
		||||
    try {
 | 
			
		||||
        RSSFeedRefreshMins = JSON.parse(fs.readFileSync('config.json')).RSSFeedRefreshMins
 | 
			
		||||
        JDPostLinksMins = JSON.parse(fs.readFileSync('config.json')).JDPostLinksMins
 | 
			
		||||
@ -17,7 +24,13 @@ async function main() {
 | 
			
		||||
        log.error('config.json file is missing.')
 | 
			
		||||
    }
 | 
			
		||||
    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')
 | 
			
		||||
    if (TelegramBotConfig) {
 | 
			
		||||
        telegrambot('Checking for links and sending to JDdownloader every ' + JDPostLinksMins + ' Minutes')
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setInterval(await feedUpdater, RSSFeedRefreshMins * 60000);
 | 
			
		||||
    setInterval(await filterFeed, JDPostLinksMins * 60000);
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,8 @@
 | 
			
		||||
    "JDPostLinksMins": 180,
 | 
			
		||||
    "Autostart": false,
 | 
			
		||||
    "OnlyHEVC": true,
 | 
			
		||||
    "TelegramBotID":"",
 | 
			
		||||
    "TelegramChatID":123456789,
 | 
			
		||||
    "Shows": [
 | 
			
		||||
        {
 | 
			
		||||
            "Name": "",
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,7 @@
 | 
			
		||||
    "cheerio": "^1.0.0-rc.11",
 | 
			
		||||
    "jdownloader-client": "^1.0.0",
 | 
			
		||||
    "lodash": "^4.17.21",
 | 
			
		||||
    "node-telegram-bot-api": "^0.59.0",
 | 
			
		||||
    "rss-parser": "^3.12.0",
 | 
			
		||||
    "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