Skip to content

Commit

Permalink
🎉 Several improvements
Browse files Browse the repository at this point in the history
- Feat: Auto back to main settings
- Feat: Show current option in settings menu
- Add description for Litterbox validity
  • Loading branch information
AnotiaWang committed Feb 17, 2022
1 parent 38a8694 commit 84f3293
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
18 changes: 12 additions & 6 deletions src/handler/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ function cb(text, data) {

const setService = (chat) => {
let t = (current) => chatData[chat].service === current ? ' ✅' : '';
return [[cb(`Catbox${t('Catbox')}`, 'setService_Catbox')], [cb(`Litterbox${t('Litterbox')}`, 'setService_Litterbox')]];
return [[
cb(`Catbox${t('Catbox')}`, 'setService_Catbox'),
cb(`Litterbox${t('Litterbox')}`, 'setService_Litterbox')],
back(chatData[chat].lang)[0]
];
}

const mainSettings = (lang) => {
const mainSettings = (chat) => {
let lang = chatData[chat].lang;
return [[
cb(strings[lang].settings_setLang, 'setLang')], [
cb(strings[lang].settings_setService, 'setService')], [
cb(strings[lang].settings_setExpr, 'setLBE')
cb(strings[lang].settings_setLang + ` (${strings[lang].name})`, 'setLang')], [
cb(strings[lang].settings_setService + ` (${chatData[chat].service})`, 'setService')], [
cb(strings[lang].settings_setExpr + ` (${chatData[chat].lbe} ${strings[lang].hour})`, 'setLBE')
]];
}

Expand All @@ -30,6 +35,7 @@ const getLanguagesButtons = (lang) => {
}
if (tmp.length > 0)
buttons.push(tmp);
buttons.push(back(lang)[0]);
return buttons;
}

Expand All @@ -42,7 +48,7 @@ const setLitterBoxExpiration = (lang, chat) => {
], [
cb(`24 ${hour}${t(24)}`, 'setLBE_24'),
cb(`72 ${hour}${t(72)}`, 'setLBE_72')
]];
], back(lang)[0]];
}

const back = (lang) => {
Expand Down
27 changes: 16 additions & 11 deletions src/handler/callbackQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,34 @@ export async function handleCallbackQuery(event) {
if (data.startsWith('setLang')) {
if (arg)
chatData[chat].lang = lang = arg;
bt = buttons.getLanguagesButtons(lang);
text = `<b>${strings[lang].settings_setLang}</b>` + strings[lang].help_setLang;
else {
bt = buttons.getLanguagesButtons(lang);
text = `<b>${strings[lang].settings_setLang}</b>` + strings[lang].help_setLang;
}
}
else if (data.startsWith('setService')) {
if (arg)
chatData[chat].service = arg;
bt = buttons.setService(chat);
text = `<b>${strings[lang].settings_setService}</b>` + strings[lang].help_setService;
else {
bt = buttons.setService(chat);
text = `<b>${strings[lang].settings_setService}</b>` + strings[lang].help_setService;
}
}
// Set Litterbox Expiration
else if (data.startsWith('setLBE')) {
if (arg)
chatData[chat].lbe = parseInt(arg);
bt = buttons.setLitterBoxExpiration(lang, chat);
text = `<b>${strings[lang].settings_setExpr}</b>`;
else {
bt = buttons.setLitterBoxExpiration(lang, chat);
text = `<b>${strings[lang].settings_setExpr}</b>` + strings[lang].help_setExpr;
}
}
else if (data === 'back') {
bt = buttons.mainSettings(lang);
// else if (data === 'back') { }
saveBotData();
if (!bt.length) {
bt = buttons.mainSettings(chat);
text = `<b>${strings[lang].settings}</b>` + strings[lang].help_settings;
}
saveBotData();
if (data !== 'back')
bt.push(buttons.back(lang)[0]);
bot.editMessage(chat, {
message: query.msgId,
text: text,
Expand Down
2 changes: 1 addition & 1 deletion src/handler/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class GeneralCommands {
bot.sendMessage(this.chat, {
message: strings[this.lang].settings,
parseMode: 'html',
buttons: buttons.mainSettings(this.lang)
buttons: buttons.mainSettings(this.chat)
}).catch(console.error);
}

Expand Down
5 changes: 3 additions & 2 deletions src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
"help_setLang": "\n\nTo contribute translations, please check the guides on <a href='https://github.com/AnotiaWang/TG_Catbox_Uploader'>GitHub</a>.",
"settings_setService": "☁ Storage service",
"help_setService": "\n\n<a href='https://catbox.moe'>Catbox</a>: No expiration, limited to 200 MB per file\n<a href='https://litterbox.catbox.moe'>Litterbox</a>: Expired after 1/12/24/72 hours, limited to 1 GB per file\n\nNote: You can only upload to one service at a time.",
"settings_setExpr": "⏰ Litterbox file expiration",
"settings_setExpr": "⏰ Litterbox file validity",
"help_setExpr": "\n\nFor files uploaded to Litterbox, they will expire after the set time. Litterbox supports 4 options below.",
"settings_back": "🔙 Back",
"saveDataSuccess": "Data saved.",
"hour": " hour(s)",
"hour": "hour(s)",
"serviceError": "Service error: {s}",
"animatedStickers": "Animated stickers are stored in .tgs format, and I currently can't convert them. Please edit the extension yourself if the file appears abnormal. You can use <a href=\"https://www.emojibest.com/tgs-to-gif\">online converter</a> or bots (like @tgstogifbot) to convert tgs to gif. ",
"fileNotDetected": "No available files detected in the message.\n\nSupported file types: documents, videos, audio, static stickers, GIF. \nTelegram server converts GIFs to mp4, so I upload them as videos.",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"settings_setService": "☁ 存储服务",
"help_setService": "\n\n<a href='https://catbox.moe'>Catbox</a> 文件不限时长,单文件限制 200 MB。\n<a href='https://litterbox.catbox.moe'>Litterbox</a> 文件有时限(1/12/24/72 小时),单文件限制 1 GB。\n\n一次只能选择将文件上传到其中一个服务。",
"settings_setExpr": "⏰ Litterbox 文件有效期",
"help_setExpr": "\n\n上传到 Litterbox 的文件会在一定时间后失效。Litterbox 支持以下时长。",
"settings_back": "🔙 返回",
"saveDataSuccess": "成功保存数据。",
"hour": " 小时",
"hour": "小时",
"serviceError": "服务出现错误:{s}",
"animatedStickers": "Telegram 动态贴纸以 .tgs 格式储存,目前不支持转换。如果文件后缀名异常,请自行修改。您可以使用<a href=\"https://www.emojibest.com/tgs-to-gif\">在线转换器</a>或机器人(如 @tgstogifbot )等工具将 .tgs 文件转换为 GIF 格式。",
"fileNotDetected": "消息中未发现可上传的文件。\n\n支持的文件类型:文档、视频、音频、静态贴纸、GIF。\nTelegram 服务器会将动图转为 mp4,因此我上传的也为视频。",
Expand Down

0 comments on commit 84f3293

Please sign in to comment.