diff --git a/README.md b/README.md index 5b09cb0..8a95ae5 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,11 @@ Kowalski is a a simple Telegram bot made in Node.js. ## Run it yourself, develop or contribute with Kowalski 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): ``` -cd kowalski +cd TelegramBot 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). @@ -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. ## config.env Functions -- **botToken**: Put your bot token that you created at [@BotFather](https://t.me/botfather), as the example above. -- **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. +- **botSource**: Put the link to your bot source code. +- **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. - **weatherKey**: Weather.com API key, used for the `/weather` command. diff --git a/config.env.example b/config.env.example index 4ed8b5b..9773d37 100644 --- a/config.env.example +++ b/config.env.example @@ -1,3 +1,4 @@ +botSource = "https://github.com/change-this/to-your-repo/" botToken = "InsertYourBotTokenHere" botAdmins = 0000000000, 00000000, 00000000 lastKey = "InsertYourLastFmApiKeyHere" diff --git a/src/bot.js b/src/bot.js index af34c08..72e6ff1 100644 --- a/src/bot.js +++ b/src/bot.js @@ -31,9 +31,10 @@ const loadCommands = () => { }; const startBot = async () => { + const botInfo = await bot.telegram.getMe(); + console.log(`${botInfo.first_name} is running...`); try { await bot.launch(); - console.log('Bot is running...'); restartCount = 0; } catch (error) { console.error('Failed to start bot:', error.message); diff --git a/src/commands/help.js b/src/commands/help.js index 469e729..45eb0be 100644 --- a/src/commands/help.js +++ b/src/commands/help.js @@ -31,7 +31,9 @@ module.exports = (bot) => { bot.command("about", spamwatchMiddleware, async (ctx) => { 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', disable_web_page_preview: true, reply_to_message_id: ctx.message.message_id diff --git a/src/commands/lastfm.js b/src/commands/lastfm.js index ed3b858..80ada6e 100644 --- a/src/commands/lastfm.js +++ b/src/commands/lastfm.js @@ -90,6 +90,7 @@ module.exports = (bot) => { const Strings = getStrings(ctx.from.language_code); const lastfmUser = users[userId]; const genericImg = "https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png"; + const botInfo = await ctx.telegram.getMe(); if (!lastfmUser) { return ctx.reply(Strings.lastFmNoSet, { @@ -109,7 +110,7 @@ module.exports = (bot) => { limit: 1 }, headers: { - 'User-Agent': "kowalski-@KowalskiNodeBot-node-telegram-bot" + 'User-Agent': `@${botInfo.username}-node-telegram-bot` } }); @@ -159,7 +160,7 @@ module.exports = (bot) => { format: 'json', }, headers: { - 'User-Agent': "kowalski-@KowalskiNodeBot-node-telegram-bot" + 'User-Agent': `@${botInfo.username}-node-telegram-bot` } }); num_plays = response_plays.data.track.userplaycount; diff --git a/src/commands/main.js b/src/commands/main.js index 8272ed1..c111603 100644 --- a/src/commands/main.js +++ b/src/commands/main.js @@ -5,7 +5,10 @@ const spamwatchMiddleware = require('../plugins/lib-spamwatch/Middleware.js')(is module.exports = (bot) => { bot.start(spamwatchMiddleware, async (ctx) => { 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', reply_to_message_id: ctx.message.message_id }); diff --git a/src/locales/english.json b/src/locales/english.json index 8dd824e..8337930 100644 --- a/src/locales/english.json +++ b/src/locales/english.json @@ -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!*", - "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", + "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 {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.", - "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", "unKnown": "Unknown", "varYes": "Yes", diff --git a/src/locales/portuguese.json b/src/locales/portuguese.json index a696a73..6519c4d 100644 --- a/src/locales/portuguese.json +++ b/src/locales/portuguese.json @@ -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!*", - "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", + "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 {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.", - "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", "unKnown": "Desconhecido", "varYes": "Sim",