Skip to content

Commit

Permalink
unsuball with confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
fengkx committed Dec 23, 2018
1 parent fcd5c96 commit 8ac1f22
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ SEND_FILE_IMPORT: Send a opml file to import subscriptions
RSS_USAGE: USAGE: /rss Output subscriptions list add "raw" to show links
USB_ALL_USAGE: USAGE: /allunsub unsubscribe all feeds
WELCOME: Welcome to [NodeRSSBot](https://github.com/fengkx/NodeRSSBot)
CONFIRM: Do you want to continue the operation
YES: YES
NO: NO
CANCEL: Canceled
4 changes: 4 additions & 0 deletions i18n/zh-cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ SEND_FILE_IMPORT: 发送 opml 文件导入订阅源
RSS_USAGE: 使用方法: /rss 输出订阅列表 加 raw 显示链接
USB_ALL_USAGE: 使用方法: /allunsub 退订所有源
WELCOME: 欢迎来到 [NodeRSSBot](https://github.com/fengkx/NodeRSSBot)
CONFIRM: 是否继续当前操作
YES:
NO:
CANCEL: 取消操作
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const {
sendError,
testUrl,
getUrlByTitle,
isAdmin
isAdmin,
confirmation
} = require('./middlewares');


Expand Down Expand Up @@ -51,6 +52,7 @@ bot.command('start', async (ctx) => {
text += `\n${i18n['RSS_USAGE']}`
text += `\n${i18n['SEND_FILE_IMPORT']}`
text += `\n${i18n['EXPORT']}`
text += `\n${i18n['USB_ALL_USAGE']}`
await ctx.replyWithMarkdown(text);
});

Expand All @@ -77,11 +79,23 @@ bot.command('unsubthis',
);

bot.command('allunsub',
sendError,
isAdmin,
// RSS.unsubAll,
confirmation
);

bot.action('UNSUB_ALL_YES',
sendError,
isAdmin,
RSS.unsubAll
);

bot.action('UNSUB_ALL_NO', async (ctx, next) => {
const cb = ctx.callbackQuery;
const res = await ctx.telegram.answerCallbackQuery(cb.id, i18n['CANCEL']);
});

bot.command('rss',
sendError,
isAdmin,
Expand Down
24 changes: 24 additions & 0 deletions middlewares/confirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const i18n = require('../i18n');
const {promisify} = require('util');
const setTimeOutPromise = promisify(setTimeout);

module.exports = async (ctx, next) => {
await ctx.telegram.deleteMessage(ctx.state.chat.id, ctx.state.processMesId);
await ctx.telegram.sendMessage(ctx.state.chat.id, i18n['CONFIRM'], {
reply_markup: {
'inline_keyboard': [
[
{
text: i18n['YES'],
callback_data: 'UNSUB_ALL_YES'
},
{
text: i18n['NO'],
callback_data: 'UNSUB_ALL_NO'
}
]
]
}
});
await next();
};

0 comments on commit 8ac1f22

Please sign in to comment.