ref: create separated verifyUserInput function again because it was n… #44

Merged
GiovaniFZ merged 2 commits from ref_userinput into main 2025-04-20 15:24:56 +00:00
4 changed files with 40 additions and 30 deletions
Showing only changes of commit 099b589d42 - Show all commits

View file

@ -1,7 +1,7 @@
# Kowalski (Node.js Telegram Bot)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![GitHub License](https://img.shields.io/github/license/ABOCN/TelegramBot)](https://github.com/abocn/TelegramBot/blob/main/LICENSE)
[![GitHub License](https://img.shields.io/github/license/abocn/TelegramBot)](https://github.com/abocn/TelegramBot/blob/main/LICENSE)
[![CodeQL](https://github.com/abocn/TelegramBot/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/abocn/TelegramBot/actions/workflows/github-code-scanning/codeql)
[![Dependabot Updates](https://github.com/abocn/TelegramBot/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/abocn/TelegramBot/actions/workflows/dependabot/dependabot-updates)

View file

@ -8,24 +8,35 @@ async function sendHelpMessage(ctx, isEditing) {
const helpText = Strings.botHelp
.replace(/{botName}/g, botInfo.first_name)
.replace(/{sourceLink}/g, process.env.botSource);
const options = {
parse_mode: 'Markdown',
disable_web_page_preview: true,
reply_to_message_id: ctx.message.message_id,
reply_markup: {
inline_keyboard: [
[{ text: Strings.mainCommands, callback_data: 'helpMain' }, { text: Strings.usefulCommands, callback_data: 'helpUseful' }],
[{ text: Strings.interactiveEmojis, callback_data: 'helpInteractive' }, { text: Strings.funnyCommands, callback_data: 'helpFunny' }],
[{ text: Strings.lastFm.helpEntry, callback_data: 'helpLast' }, { text: Strings.animalCommands, callback_data: 'helpAnimals' }],
[{ text: Strings.ytDownload.helpEntry, callback_data: 'helpYouTube' }, { text: Strings.ponyApi.helpEntry, callback_data: 'helpMLP' }]
]
}
function getMessageId(ctx) {
return ctx.message?.message_id || ctx.callbackQuery?.message?.message_id;
};
const createOptions = (ctx, includeReplyTo = false) => {
const options = {
parse_mode: 'Markdown',
disable_web_page_preview: true,
reply_markup: {
inline_keyboard: [
[{ text: Strings.mainCommands, callback_data: 'helpMain' }, { text: Strings.usefulCommands, callback_data: 'helpUseful' }],
[{ text: Strings.interactiveEmojis, callback_data: 'helpInteractive' }, { text: Strings.funnyCommands, callback_data: 'helpFunny' }],
[{ text: Strings.lastFm.helpEntry, callback_data: 'helpLast' }, { text: Strings.animalCommands, callback_data: 'helpAnimals' }],
[{ text: Strings.ytDownload.helpEntry, callback_data: 'helpYouTube' }, { text: Strings.ponyApi.helpEntry, callback_data: 'helpMLP' }]
]
}
};
if (includeReplyTo) {
const messageId = getMessageId(ctx);
if (messageId) {
options.reply_to_message_id = messageId;
};
};
return options;
};
if (isEditing) {
await ctx.editMessageText(helpText, options);
await ctx.editMessageText(helpText, createOptions(ctx));
} else {
await ctx.reply(helpText, options);
}
await ctx.reply(helpText, createOptions(ctx, true));
};
}
module.exports = (bot) => {
@ -36,7 +47,6 @@ module.exports = (bot) => {
bot.command("about", spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code);
const aboutMsg = Strings.botAbout.replace(/{sourceLink}/g, `${process.env.botSource}`);
ctx.reply(aboutMsg, {
parse_mode: 'Markdown',
disable_web_page_preview: true,

View file

@ -12,7 +12,7 @@ async function getUserInfo(ctx) {
userInfo = Strings.userInfo
.replace('{userName}', `${ctx.from.first_name} ${lastName}` || Strings.varStrings.varUnknown)
.replace('{userId}', ctx.from.id || Strings.varStrings.varUnknown)
.replace('{userHandle}', ctx.from.username ? `@${ctx.from.username}` : Strings.varStrings.varStrings.varNone)
.replace('{userHandle}', ctx.from.username ? `@${ctx.from.username}` : Strings.varStrings.varNone)
.replace('{userPremium}', ctx.from.is_premium ? Strings.varStrings.varYes : Strings.varStrings.varNo)
.replace('{userLang}', ctx.from.language_code || Strings.varStrings.varUnknown);
@ -25,7 +25,7 @@ async function getChatInfo(ctx) {
chatInfo = Strings.chatInfo
.replace('{chatId}', ctx.chat.id || Strings.varStrings.varUnknown)
.replace('{chatName}', ctx.chat.title || Strings.varStrings.varUnknown)
.replace('{chatHandle}', ctx.chat.username ? `@${ctx.chat.username}` : Strings.varStrings.varStrings.varNone)
.replace('{chatHandle}', ctx.chat.username ? `@${ctx.chat.username}` : Strings.varStrings.varNone)
.replace('{chatMembersCount}', await ctx.getChatMembersCount(ctx.chat.id || Strings.varStrings.varUnknown))
.replace('{chatType}', ctx.chat.type || Strings.varStrings.varUnknown)
.replace('{isForum}', ctx.chat.is_forum ? Strings.varStrings.varYes : Strings.varStrings.varNo);

View file

@ -50,12 +50,12 @@ module.exports = (bot) => {
charactersArray.push({
id: character.id,
name: character.name,
alias: aliases.length > 0 ? aliases.join(', ') : 'None',
alias: aliases.length > 0 ? aliases.join(', ') : Strings.varStrings.varNone,
url: character.url,
sex: character.sex,
residence: character.residence ? character.residence.replace(/\n/g, ' / ') : 'None',
occupation: character.occupation ? character.occupation.replace(/\n/g, ' / ') : 'None',
kind: character.kind ? character.kind.join(', ') : 'None',
residence: character.residence ? character.residence.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
occupation: character.occupation ? character.occupation.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
kind: character.kind ? character.kind.join(', ') : Strings.varStrings.varNone,
image: character.image
});
});
@ -120,9 +120,9 @@ module.exports = (bot) => {
episode: episode.episode,
overall: episode.overall,
airdate: episode.airdate,
storyby: episode.storyby ? episode.storyby.replace(/\n/g, ' / ') : 'None',
writtenby: episode.writtenby ? episode.writtenby.replace(/\n/g, ' / ') : 'None',
storyboard: episode.storyboard ? episode.storyboard.replace(/\n/g, ' / ') : 'None',
storyby: episode.storyby ? episode.storyby.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
writtenby: episode.writtenby ? episode.writtenby.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
storyboard: episode.storyboard ? episode.storyboard.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
});
});
};
@ -192,10 +192,10 @@ module.exports = (bot) => {
series: comic.series,
image: comic.image,
url: comic.url,
writer: comic.writer ? comic.writer.replace(/\n/g, ' / ') : 'None',
artist: comic.artist ? comic.artist.replace(/\n/g, ' / ') : 'None',
colorist: comic.colorist ? comic.colorist.replace(/\n/g, ' / ') : 'None',
letterer: letterers.length > 0 ? letterers.join(', ') : 'None',
writer: comic.writer ? comic.writer.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
artist: comic.artist ? comic.artist.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
colorist: comic.colorist ? comic.colorist.replace(/\n/g, ' / ') : Strings.varStrings.varNone,
letterer: letterers.length > 0 ? letterers.join(', ') : Strings.varStrings.varNone,
editor: comic.editor
});
});