Compare commits

..

3 Commits

Author SHA1 Message Date
Fabian Stamm
791b601dec Increase delay between checks to 15 minutes
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2023-04-26 20:03:27 +02:00
Fabian Stamm
1082dd7a71 Fix bug
All checks were successful
continuous-integration/drone/tag Build is passing
2023-04-26 19:58:59 +02:00
Fabian Stamm
96d457ab11 Add small UX improvements
All checks were successful
continuous-integration/drone/tag Build is passing
2023-04-26 19:53:45 +02:00
3 changed files with 24 additions and 11 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "rss-telegram-bot", "name": "rss-telegram-bot",
"version": "2.0.0", "version": "2.0.3",
"main": "lib/index.js", "main": "lib/index.js",
"author": "Fabian Stamm <dev@fabianstamm.de>", "author": "Fabian Stamm <dev@fabianstamm.de>",
"license": "MIT", "license": "MIT",

View File

@ -98,11 +98,12 @@ async function checkFeed(feed: Feed) {
// feed.addItems(newItems); // feed.addItems(newItems);
} }
// const FEED_CHECK_INTERVAL = 1000 * 60 * 60; const FEED_CHECK_INTERVAL = 1000 * 60 * 15;
const FEED_CHECK_INTERVAL = 1000 * 30; // const FEED_CHECK_INTERVAL = 1000 * 30;
export default async function checkFeeds() { export default async function checkFeeds() {
while (true) { while (true) {
Logging.info("Checking for feeds to synchronize");
let feed = await AppDataSource.manager.findOne(Feed, { let feed = await AppDataSource.manager.findOne(Feed, {
where: { where: {
lastCheck: LessThan(new Date(Date.now() - FEED_CHECK_INTERVAL)) lastCheck: LessThan(new Date(Date.now() - FEED_CHECK_INTERVAL))
@ -113,14 +114,14 @@ export default async function checkFeeds() {
}) })
if (!feed) { if (!feed) {
await new Promise(y => setTimeout(y, 1000)); await new Promise(y => setTimeout(y, 10000));
continue; continue;
} }
feed.lastCheck = new Date(); feed.lastCheck = new Date();
await AppDataSource.manager.save(feed); await AppDataSource.manager.save(feed);
Promise.resolve(async () => { Promise.resolve().then(async () => {
await checkFeed(feed); await checkFeed(feed);
}).catch(err => { }).catch(err => {
Logging.warn("Error while checking feed: %s", feed.url); Logging.warn("Error while checking feed: %s", feed.url);

View File

@ -64,23 +64,35 @@ bot.command("delete", botHandler(async ctx => {
bot.on("callback_query", botHandler(async ctx => { bot.on("callback_query", botHandler(async ctx => {
Logging.info("Callback Query received"); Logging.info("Callback Query received");
const remove_options = () => { const remove_options = (message: string) => {
ctx.editMessageReplyMarkup({ ctx.editMessageReplyMarkup({
inline_keyboard: [] inline_keyboard: [],
}) })
ctx.editMessageText(message)
} }
let data = (ctx.callbackQuery as any).data; let data = (ctx.callbackQuery as any).data;
if (!data) { if (!data) {
ctx.answerCbQuery("Invalid data"); ctx.answerCbQuery("Invalid data");
remove_options(); remove_options("Delete failed. Invalid data received.");
return return
} }
let [action, id] = data.split(":"); let [action, id] = data.split(":");
if (!action || !id) { if (!action || !id) {
ctx.answerCbQuery("Invalid data"); ctx.answerCbQuery("Invalid data");
remove_options(); remove_options("Delete failed. Invalid data received.");
return
}
let feed = await AppDataSource.manager.findOne(Feed, {
where: {
id: Number(id)
}
});
if (!feed) {
ctx.answerCbQuery("Invalid action");
remove_options("Delete failed. Feed not available.");
return return
} }
@ -100,12 +112,12 @@ bot.on("callback_query", botHandler(async ctx => {
} }
} else { } else {
ctx.answerCbQuery("Invalid action"); ctx.answerCbQuery("Invalid action");
remove_options(); remove_options("Delete failed. Invalid data received.");
return return
} }
ctx.answerCbQuery("Success"); ctx.answerCbQuery("Success");
remove_options(); remove_options("Deleted feed: " + feed.url);
})); }));
bot.on(message("text", "entities"), botHandler(async ctx => { bot.on(message("text", "entities"), botHandler(async ctx => {