Made the bot more generic now

This commit is contained in:
Lucas Gabriel 2025-01-10 10:40:18 -03:00
parent c63efe5e67
commit ad27a25d1f
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
8 changed files with 24 additions and 15 deletions

View File

@ -13,11 +13,11 @@ Kowalski is a a simple Telegram bot made in Node.js.
## Run it yourself, develop or contribute with Kowalski ## Run it yourself, develop or contribute with Kowalski
First, clone the repo with Git: First, clone the repo with Git:
``` ```
git clone https://github.com/ABOCN/TelegramBot kowalski git clone https://github.com/ABOCN/TelegramBot
``` ```
And now, init the submodules with these commands (this is very important): And now, init the submodules with these commands (this is very important):
``` ```
cd kowalski cd TelegramBot
git submodule update --init --recursive git submodule update --init --recursive
``` ```
Next, inside the repository directory, create a `config.env` file with some content, which you can see the [example .env file](config.env.example) to fill info with. To see the meaning of each one, see [the Functions section](#configenv-functions). Next, inside the repository directory, create a `config.env` file with some content, which you can see the [example .env file](config.env.example) to fill info with. To see the meaning of each one, see [the Functions section](#configenv-functions).
@ -26,8 +26,9 @@ After editing the file, save all changes and run the bot with ``npm start``.
- To deal with dependencies, just run ``npm install`` or ``npm i`` at any moment to install all of them. - To deal with dependencies, just run ``npm install`` or ``npm i`` at any moment to install all of them.
## config.env Functions ## config.env Functions
- **botToken**: Put your bot token that you created at [@BotFather](https://t.me/botfather), as the example above. - **botSource**: Put the link to your bot source code.
- **botAdmins**: Put the ID of the people responsible for managing the bot (as the example above). They can use some administrative + exclusive commands on any group. - **botToken**: Put your bot token that you created at [@BotFather](https://t.me/botfather).
- **botAdmins**: Put the ID of the people responsible for managing the bot. They can use some administrative + exclusive commands on any group.
- **lastKey**: Last.fm API key, for use on `lastfm.js` functions, like see who is listening to what song and etc. - **lastKey**: Last.fm API key, for use on `lastfm.js` functions, like see who is listening to what song and etc.
- **weatherKey**: Weather.com API key, used for the `/weather` command. - **weatherKey**: Weather.com API key, used for the `/weather` command.

View File

@ -1,3 +1,4 @@
botSource = "https://github.com/change-this/to-your-repo/"
botToken = "InsertYourBotTokenHere" botToken = "InsertYourBotTokenHere"
botAdmins = 0000000000, 00000000, 00000000 botAdmins = 0000000000, 00000000, 00000000
lastKey = "InsertYourLastFmApiKeyHere" lastKey = "InsertYourLastFmApiKeyHere"

View File

@ -31,9 +31,10 @@ const loadCommands = () => {
}; };
const startBot = async () => { const startBot = async () => {
const botInfo = await bot.telegram.getMe();
console.log(`${botInfo.first_name} is running...`);
try { try {
await bot.launch(); await bot.launch();
console.log('Bot is running...');
restartCount = 0; restartCount = 0;
} catch (error) { } catch (error) {
console.error('Failed to start bot:', error.message); console.error('Failed to start bot:', error.message);

View File

@ -31,7 +31,9 @@ module.exports = (bot) => {
bot.command("about", spamwatchMiddleware, async (ctx) => { bot.command("about", spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code); const Strings = getStrings(ctx.from.language_code);
ctx.reply(Strings.botAbout, { const aboutMsg = Strings.botAbout.replace("{sourceLink}", `${process.env.botSource}`);
ctx.reply(aboutMsg, {
parse_mode: 'Markdown', parse_mode: 'Markdown',
disable_web_page_preview: true, disable_web_page_preview: true,
reply_to_message_id: ctx.message.message_id reply_to_message_id: ctx.message.message_id

View File

@ -90,6 +90,7 @@ module.exports = (bot) => {
const Strings = getStrings(ctx.from.language_code); const Strings = getStrings(ctx.from.language_code);
const lastfmUser = users[userId]; const lastfmUser = users[userId];
const genericImg = "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"; const genericImg = "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png";
const botInfo = await ctx.telegram.getMe();
if (!lastfmUser) { if (!lastfmUser) {
return ctx.reply(Strings.lastFmNoSet, { return ctx.reply(Strings.lastFmNoSet, {
@ -109,7 +110,7 @@ module.exports = (bot) => {
limit: 1 limit: 1
}, },
headers: { headers: {
'User-Agent': "kowalski-@KowalskiNodeBot-node-telegram-bot" 'User-Agent': `@${botInfo.username}-node-telegram-bot`
} }
}); });
@ -159,7 +160,7 @@ module.exports = (bot) => {
format: 'json', format: 'json',
}, },
headers: { headers: {
'User-Agent': "kowalski-@KowalskiNodeBot-node-telegram-bot" 'User-Agent': `@${botInfo.username}-node-telegram-bot`
} }
}); });
num_plays = response_plays.data.track.userplaycount; num_plays = response_plays.data.track.userplaycount;

View File

@ -5,7 +5,10 @@ const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(is
module.exports = (bot) => { module.exports = (bot) => {
bot.start(spamwatchMiddleware, async (ctx) => { bot.start(spamwatchMiddleware, async (ctx) => {
const Strings = getStrings(ctx.from.language_code); const Strings = getStrings(ctx.from.language_code);
ctx.reply(Strings.botWelcome, { const botInfo = await ctx.telegram.getMe();
const startMsg = Strings.botWelcome.replace('{botName}', botInfo.first_name);
ctx.reply(startMsg, {
parse_mode: 'Markdown', parse_mode: 'Markdown',
reply_to_message_id: ctx.message.message_id reply_to_message_id: ctx.message.message_id
}); });

View File

@ -1,8 +1,8 @@
{ {
"botWelcome": "*Hello! I am Kowalski!*\nI was made with love by some nerds who really love programming!\n\n*Before using, you need to read the privacy policy (/privacy) to understand where your data goes when using this bot.*\n\nAlso, you can use /help to see the bot commands!\n\n*Special thanks to @givfnz2 for his many contributions to the bot!*", "botWelcome": "*Hello! I am {botName}!*\nI was made with love by some nerds who really love programming!\n\n*Before using, you need to read the privacy policy (/privacy) to understand where your data goes when using this bot.*\n\nAlso, you can use /help to see the bot commands!\n\n*Special thanks to @givfnz2 for his many contributions to the bot!*",
"botHelp": "*Hey, I'm Kowalski, a simple bot made entirely from scratch in Telegraf and Node.js by some nerds who really love programming.*\n\nClick on the buttons below to see which commands you can use!\n", "botHelp": "*Hey, I'm {botName}, a simple bot made entirely from scratch in Telegraf and Node.js by some nerds who really love programming.*\n\nClick on the buttons below to see which commands you can use!\n",
"botPrivacy": "Check out [this link](https://blog.lucmsilva.com/posts/lynx-privacy-policy) to read the bot's privacy policy.", "botPrivacy": "Check out [this link](https://blog.lucmsilva.com/posts/lynx-privacy-policy) to read the bot's privacy policy.",
"botAbout": "*About the bot*\n\nKowalski was originally created by [Lucas Gabriel (lucmsilva)](https://github.com/lucmsilva651), now maintained by several people.\n\nThe bot's purpose is to bring fun to your groups here on Telegram in a relaxed and simple way. The bot also features some very useful commands, which you can see using the help command (/help).\n\nSee the source code: [Click here to go to GitHub](https://github.com/abocn/TelegramBot)", "botAbout": "*About the bot*\n\nThe bot base was originally created by [Lucas Gabriel (lucmsilva)](https://github.com/lucmsilva651), now maintained by several people.\n\nThe bot's purpose is to bring fun to your groups here on Telegram in a relaxed and simple way. The bot also features some very useful commands, which you can see using the help command (/help).\n\nSee the source code: [Click here to go to GitHub]({sourceLink})",
"aboutBot": "About the bot", "aboutBot": "About the bot",
"unKnown": "Unknown", "unKnown": "Unknown",
"varYes": "Yes", "varYes": "Yes",

View File

@ -1,8 +1,8 @@
{ {
"botWelcome": "*Olá! Eu sou o Kowalski!*\nFui feito com carinho por uns nerds que gostam de programação!\n\n*Antes de usar, você precisa ler a política de privacidade (/privacy) para entender onde seus dados vão ao usar este bot.*\n\nAlém disso, você pode usar /help para ver os comandos do bot!\n\n*Agradecimento especial ao @givfnz2 pelas suas várias contribuições ao bot!*", "botWelcome": "*Olá! Eu sou o {botName}!*\nFui feito com carinho por uns nerds que gostam de programação!\n\n*Antes de usar, você precisa ler a política de privacidade (/privacy) para entender onde seus dados vão ao usar este bot.*\n\nAlém disso, você pode usar /help para ver os comandos do bot!\n\n*Agradecimento especial ao @givfnz2 pelas suas várias contribuições ao bot!*",
"botHelp": "*Oi, eu sou o Kowalski, um bot simples feito do zero em Telegraf e Node.js por uns nerds que gostam de programação.*\n\nClique nos botões abaixo para ver quais comandos você pode usar!\n", "botHelp": "*Oi, eu sou o {botName}, um bot simples feito do zero em Telegraf e Node.js por uns nerds que gostam de programação.*\n\nClique nos botões abaixo para ver quais comandos você pode usar!\n",
"botPrivacy": "Acesse [este link](https://blog.lucmsilva.com/posts/lynx-privacy-policy) para ler a política de privacidade do bot.", "botPrivacy": "Acesse [este link](https://blog.lucmsilva.com/posts/lynx-privacy-policy) para ler a política de privacidade do bot.",
"botAbout": "*Sobre o bot*\n\nKowalski foi feito originalmente por [Lucas Gabriel (lucmsilva)](https://github.com/lucmsilva651), agora sendo mantido por várias pessoas.\n\nA intenção do bot é trazer diversão para os seus grupos aqui no Telegram de uma maneira bem descontraida e simples. O bot também conta com alguns comandos bem úteis, que você consegue ver com o comando de ajuda (/help).\n\nVeja o código fonte: [Clique aqui para ir ao GitHub](https://github.com/abocn/TelegramBot)", "botAbout": "*Sobre o bot*\n\nA base deste bot foi feita originalmente por [Lucas Gabriel (lucmsilva)](https://github.com/lucmsilva651), agora sendo mantido por várias pessoas.\n\nA intenção do bot é trazer diversão para os seus grupos aqui no Telegram de uma maneira bem descontraida e simples. O bot também conta com alguns comandos bem úteis, que você consegue ver com o comando de ajuda (/help).\n\nVeja o código fonte: [Clique aqui para ir ao GitHub]({sourceLink})",
"aboutBot": "Sobre o bot", "aboutBot": "Sobre o bot",
"unKnown": "Desconhecido", "unKnown": "Desconhecido",
"varYes": "Sim", "varYes": "Sim",