ref: replace "ctx.from.language_code" with a function to get the language code and fix ts implementation for "reply_to_message_id" (#51)
Co-authored-by: Lucas Gabriel <lucmsilva651@gmail.com>
This commit is contained in:
parent
6dce40d333
commit
87c987c16d
17 changed files with 193 additions and 160 deletions
|
@ -5,6 +5,8 @@ import spamwatchMiddlewareModule from '../spamwatch/Middleware';
|
|||
import axios from 'axios';
|
||||
import verifyInput from '../plugins/verifyInput';
|
||||
import { Telegraf, Context } from 'telegraf';
|
||||
import { languageCode } from '../utils/language-code';
|
||||
import { replyToMessageId } from '../utils/reply-to-message-id';
|
||||
|
||||
const spamwatchMiddleware = spamwatchMiddlewareModule(isOnSpamWatch);
|
||||
|
||||
|
@ -47,24 +49,24 @@ interface Comic {
|
|||
editor: string;
|
||||
}
|
||||
|
||||
function capitalizeFirstLetter(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
function capitalizeFirstLetter(letter: string) {
|
||||
return letter.charAt(0).toUpperCase() + letter.slice(1);
|
||||
}
|
||||
|
||||
export default (bot: Telegraf<Context>) => {
|
||||
bot.command("mlp", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
||||
const Strings = getStrings(languageCode(ctx));
|
||||
const reply_to_message_id = replyToMessageId(ctx);
|
||||
|
||||
ctx.reply(Strings.ponyApi.helpDesc, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
disable_web_page_preview: true,
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||
});
|
||||
});
|
||||
|
||||
bot.command("mlpchar", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
||||
const reply_to_message_id = replyToMessageId(ctx);
|
||||
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
const { noCharName } = Strings.ponyApi
|
||||
|
||||
|
@ -118,30 +120,27 @@ export default (bot: Telegraf<Context>) => {
|
|||
ctx.replyWithPhoto(charactersArray[0].image[0], {
|
||||
caption: `${result}`,
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
disable_web_page_preview: true,
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||
});
|
||||
} else {
|
||||
ctx.reply(Strings.ponyApi.noCharFound, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
} catch (error) {
|
||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||
ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
bot.command("mlpep", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
||||
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
const reply_to_message_id = replyToMessageId(ctx);
|
||||
|
||||
const { noEpisodeNum } = Strings.ponyApi
|
||||
|
||||
|
@ -156,7 +155,7 @@ export default (bot: Telegraf<Context>) => {
|
|||
const episodeArray: Episode[] = [];
|
||||
|
||||
if (Array.isArray(response.data.data)) {
|
||||
response.data.data.forEach(episode => {
|
||||
response.data.data.forEach((episode: Episode) => {
|
||||
episodeArray.push({
|
||||
id: episode.id,
|
||||
name: episode.name,
|
||||
|
@ -189,30 +188,29 @@ export default (bot: Telegraf<Context>) => {
|
|||
ctx.replyWithPhoto(episodeArray[0].image, {
|
||||
caption: `${result}`,
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
disable_web_page_preview: true,
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||
});
|
||||
} else {
|
||||
ctx.reply(Strings.ponyApi.noEpisodeFound, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
} catch (error) {
|
||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||
ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
bot.command("mlpcomic", spamwatchMiddleware, async (ctx: Context & { message: { text: string } }) => {
|
||||
const Strings = getStrings(ctx.from?.language_code || 'en');
|
||||
const Strings = getStrings(languageCode(ctx) || 'en');
|
||||
const userInput = ctx.message.text.split(' ').slice(1).join(' ').replace(" ", "+");
|
||||
const reply_to_message_id = replyToMessageId(ctx);
|
||||
|
||||
const { noComicName } = Strings.ponyApi
|
||||
|
||||
|
@ -265,23 +263,21 @@ export default (bot: Telegraf<Context>) => {
|
|||
ctx.replyWithPhoto(comicArray[0].image, {
|
||||
caption: `${result}`,
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
disable_web_page_preview: true,
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
...({ reply_to_message_id, disable_web_page_preview: true })
|
||||
});
|
||||
} else {
|
||||
ctx.reply(Strings.ponyApi.noComicFound, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
} catch (error) {
|
||||
const message = Strings.ponyApi.apiErr.replace('{error}', error.message);
|
||||
ctx.reply(message, {
|
||||
parse_mode: 'Markdown',
|
||||
// @ts-ignore
|
||||
reply_to_message_id: ctx.message.message_id
|
||||
|
||||
...({ reply_to_message_id })
|
||||
});
|
||||
};
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue