Skip to content

Commit

Permalink
refactor langs dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
chupapee committed Jul 22, 2023
1 parent 5f11169 commit 42bfae0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
10 changes: 4 additions & 6 deletions src/entities/twitter/lib/createActionsKeyboard.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { InlineKeyboardButton } from 'typegram';

export const createActionsKeyboard = (
actionsList: string[],
ACTION_ID: string
) => {
export const createActionsKeyboard = (actionsList: string[]) => {
return actionsList.reduce(
(acc: InlineKeyboardButton[][], text, i) => {
const cbData = `tweetStats-${text}`;
if (i > 2) {
acc[1].push({ text, callback_data: ACTION_ID });
acc[1].push({ text, callback_data: cbData });
return acc;
}
acc[0].push({ text, callback_data: ACTION_ID });
acc[0].push({ text, callback_data: cbData });
return acc;
},
[[], []]
Expand Down
2 changes: 1 addition & 1 deletion src/features/instagram/send-many-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const sendManyFiles = async ({
);
}

/** and then, send other videos links */
/** send other videos links */
await ctx.reply(
`<a href='${ctx.i18n.t('otherVideos')} ${
links[0].source
Expand Down
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,28 @@ bot.command('feedback', async (ctx) => {
await ctx.scene.enter(feedbackScene.id);
});

/** The response to the 'tweet stats' inline_keyboard press is due to the fact that
* after processing the link, the scene is exited,
* so its needs to handle the button click here */
bot.use(async (ctx, next) => {
try {
if (
'data' in ctx.callbackQuery! &&
ctx.callbackQuery.data.includes('tweetStats')
) {
const text = ctx.callbackQuery.data.split('-')[1];
await ctx.answerCbQuery(text);
}
} catch {}
return next();
});

bot.use(async (ctx, next) => {
/** While the user is in a certain scene,
* new commands are not processed */
const isStarted = ctx.state.isStarted;
const isRunning = ctx.scene.current;

/** While the user is in a certain scene,
* new commands are not processed */
if (!isStarted && isRunning) {
const { message_id } = await ctx.reply(ctx.i18n.t('pleaseWait'));
addMsgToRemoveList(message_id, ctx);
Expand Down
13 changes: 2 additions & 11 deletions src/scenes/twitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
import { onServiceFinish, onServiceInit } from '@features/scenes';
import { IContextBot } from '@shared/config';

const ACTION_ID = 'tweetMetrics';

export const twitterScene = new Scenes.BaseScene<IContextBot>('twitterScene');

twitterScene.enter(async (ctx) => {
Expand All @@ -26,10 +24,7 @@ twitterScene.enter(async (ctx) => {
originalLink
);

const actionsKeyboard = createActionsKeyboard(
actionsBtn,
ACTION_ID
);
const actionsKeyboard = createActionsKeyboard(actionsBtn);

if (mediaFiles.length > 0) {
await ctx.replyWithMediaGroup(
Expand All @@ -49,7 +44,7 @@ twitterScene.enter(async (ctx) => {
};
})
);
await ctx.reply(ctx.i18n.t('tweetMetrics'), {
await ctx.reply(ctx.i18n.t('tweetStats'), {
reply_markup: { inline_keyboard: actionsKeyboard },
});
return;
Expand Down Expand Up @@ -93,7 +88,3 @@ twitterScene.enter(async (ctx) => {
})
);
});

twitterScene.action(ACTION_ID, async (ctx) => {
await ctx.answerCbQuery();
});
12 changes: 2 additions & 10 deletions src/shared/config/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"//start_command": "",
"start": "🔗 Please send the link",
"processingLink": "⏳ Processing the link, it will take no more than a minute",
"invalidLink": "🚫 Please send a valid link.",
"pleaseWait": "⚡️ Your request is being processed\n⌛️ Please be patient",
"invalidLink": "🚫 Please send a valid link.",

"//insta_scene": "",
"downloadAll": "📥 Download all",
"containsManyLinks": "🔗 The link contains multiple media files. Please select which one you'd like to download:",
"linksFound": "✅ Link successfully processed! Click to download:",
"otherVideos": "🎥 Other videos from",

"//tiktok-scene": "",
Expand All @@ -18,23 +15,18 @@


"//twitter_scene": "",
"tweetMetrics": "📈 Tweet metrics",
"tweetStats": "📊 | Tweet stats",
"TweetUnavailable": "🔒 Unfortunately, this tweet is protected and unavailable for viewing",

"//you_scene": "",
"clickToDownload": "⬇️ Click the link to download the video:",

"//feedback-scene": "",
"feedbackExample": "Here you can send a message to the developer! 👤\nThink carefully, express your thought fully, and fit it into one message ✍️\n\nBelow are examples of different types of feedback you can send:\n- Hi! I would like to suggest adding feature X, which would allow us to do Y 📈\n- Hi! I noticed a bug in function X when I do Y 🛠",
"feedbackReceived": "✉️ Feedback received!\nYou can continue using the bot 🚀",

"//general": "",
"chooseQuality": "🎥 Choose the resolution:",
"smthWentWrong": "❌ Oops, something went wrong. Please try again.",
"uploadingMedia": "📤 Uploading to Telegram...",
"uploadingVideo": "📤 Uploading the video to Telegram...",
"savedByBot": "📤 Saved by: @insta_twitter_youtube_bot",

"botUpTechIssues": "Hey! 👋\nTechnical issues have been resolved 🛠✅\nYou can use the bot again 🚀",
"botUpText": "⚡️ ***Update*** ⚡️\n\n💡 Added support for ***TikTok links!***\n🛠 Additionally, minor bugs with Twitter links have been fixed. You can try re-uploading the links that had errors"
}
9 changes: 1 addition & 8 deletions src/shared/config/locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"invalidLink": "🚫 Отправьте корректную ссылку",

"//insta-scene": "",
"downloadAll": "📥 Скачать все",
"containsManyLinks": "🔗 Ссылка содержит несколько медиа файлов, выберите какой хотите скачать:",
"linksFound": "✅ Ссылка успешно обработана! Нажмите чтобы скачать:",
"otherVideos": "🎥 Остальное видео от",

"//tiktok-scene": "",
Expand All @@ -17,22 +14,18 @@
"incorrectLink": "❌ Не удалось спарсить ссылку(\nВозможно с файлом что-то не так...",

"//twitter-scene": "",
"tweetMetrics": "📈 Метрики твита",
"tweetStats": "📊 | Статистика твита",
"TweetUnavailable": "🔒 К сожалению, твит защищён и недоступен для просмотра",

"//you-scene": "",
"clickToDownload": "▶️ Перейдите по ссылке чтобы скачать видео:",

"//feedback-scene": "",
"feedbackExample": "Здесь ты можешь отправить сообщение разработчику! 👤\nПодумай как следует, вырази свою мысль полностью и умести ее в одно сообщение ✍️\n\nНиже приведены примеры различного типа обратной связи, которую можно отправить:\n- Привет! Я хотел бы предложить добавить функцию X, которая позволит нам Y 📈\n- Привет! Я заметил ошибку в функции X, когда я делаю Y 🛠",
"feedbackReceived": "✉️ Обратная связь принята!\nМожно продолжить пользоваться ботом 🚀",

"//general": "",
"smthWentWrong": "❌ Что-то пошло не так, попробуйте заново.",
"uploadingMedia": "📤 Загружаем в телеграм...",
"uploadingVideo": "📤 Загружаем видео в телеграм...",
"savedByBot": "📤 Загружено при помощи: @insta_twitter_youtube_bot",
"chooseQuality": "🎥 Выберите разрешение:",
"botUpTechIssues": "Привет! 👋\nТехнические неполадки разрешены 🛠✅\nМожете вновь пользоваться ботом 🚀",
"botUpText": "⚡️ ***Обновление*** ⚡️\n\n💡 Теперь поддерживаются ***ссылки с TikTok***!\n🛠 Также исправлены незначительные баги со ссылками с twitter, можете попробовать загрузить заново ссылки с ошибками"
}

0 comments on commit 42bfae0

Please sign in to comment.