From 33f76fd806dfc26da8d4b77a333ad829e9925177 Mon Sep 17 00:00:00 2001 From: A Bunch of Computer Nerds Date: Sun, 8 Dec 2024 21:47:32 -0300 Subject: [PATCH] Fixed bot admin handling + modified README --- README.md | 26 +++++++++----------------- config.env.example | 4 ++++ src/commands/admin.js | 2 +- src/commands/crew.js | 3 ++- 4 files changed, 16 insertions(+), 19 deletions(-) create mode 100644 config.env.example diff --git a/README.md b/README.md index 9852b8a..7fcb353 100644 --- a/README.md +++ b/README.md @@ -23,27 +23,19 @@ And now, init the submodules with these commands (this is very important): cd lynx git submodule update --init --recursive ``` -Next, inside the repository directory, go to props folder and create a `config.json` file with the following content: -``` -{ - "botToken": "0000000000:AAAaaAAaaaaAaAaaAAAaaaAaaaaAAAAAaaa", - "admins": [0000000000, 1111111111, 2222222222], - "lastKey": "0000a000a0000aaa0a00a0aaa0a000000", - "lastSecret": "0000a000a0a0000aa0000aa00000000a", - "weatherKey": "0000a000a0000aaa0a00a0aaa0a000000" -} -``` -- **botToken**: Put your bot token that you created at [@BotFather](https://t.me/botfather), as the example above. -- **admins**: 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. -- **lastKey**: Last.fm API key, for use on `lastfm.js` functions, like see who is listening to what song and etc. -- **lastSecret**: Last.fm API secret (optional), which has the "same" purpose as the API key above. -- **weatherKey**: Weather.com API key, used for the `/weather` command +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). 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 any of them. +- 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. +- **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. ## Note -- Take care of your ``config.json`` file, as it is so much important and needs to be secret (like your passwords), as anyone can do whatever they want to the bot with this token! +- Take care of your ``config.env`` file, as it is so much important and needs to be secret (like your passwords), as anyone can do whatever they want to the bot with this token! ## About/License BSD-3-Clause - 2024 Lucas Gabriel (lucmsilva). diff --git a/config.env.example b/config.env.example new file mode 100644 index 0000000..4ed8b5b --- /dev/null +++ b/config.env.example @@ -0,0 +1,4 @@ +botToken = "InsertYourBotTokenHere" +botAdmins = 0000000000, 00000000, 00000000 +lastKey = "InsertYourLastFmApiKeyHere" +weatherKey = "InsertYourWeatherDotComApiKeyHere" \ No newline at end of file diff --git a/src/commands/admin.js b/src/commands/admin.js index ef5929c..49ee611 100644 --- a/src/commands/admin.js +++ b/src/commands/admin.js @@ -9,7 +9,7 @@ async function collectInfo(ctx) { const userId = parseInt(ctx.message.text.split(' ')[1], 10); const admins = await ctx.telegram.getChatAdministrators(chatId); const isAdmin = admins.some(admin => admin.user.id === adminId); - const onCrew = process.env.botAdmins.includes(adminId); + const onCrew = JSON.parse("[" + process.env.botAdmins + "]"); return { Strings, chatId, userId, isAdmin, onCrew }; } diff --git a/src/commands/crew.js b/src/commands/crew.js index 9f03684..80cc8c4 100644 --- a/src/commands/crew.js +++ b/src/commands/crew.js @@ -53,7 +53,8 @@ function getSystemInfo() { async function handleAdminCommand(ctx, action, successMessage, errorMessage) { const Strings = getStrings(ctx.from.language_code); const userId = ctx.from.id; - if (process.env.botAdmins.includes(userId)) { + const adminArray = JSON.parse("[" + process.env.botAdmins + "]"); + if (adminArray.includes(userId)) { try { await action(); ctx.reply(successMessage, {