Skip to content

Commit fdcac99

Browse files
authored
Merge pull request #4 from Kf637/main
Added support for role-based access and fixed deprecated ephemeral response flag
2 parents 13bd909 + 24aa8f5 commit fdcac99

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ Use the `/htop` command to view a live list of the most resource-intensive proce
3636
The `/htop` command is restricted to a specific Discord user ID for security reasons. Only the designated user can run this command to view system processes.
3737

3838
The command code is located at [`src/commands/htop.js`](./src/commands/htop.js).
39+
To specify who can run the command, update the `ALLOWED_USER_ID` or `ALLOWED_ROLE_ID` constants in `src/commands/htop.js`:
40+
- If both are set, the command will allow access if the user matches either the user ID or the role ID (logical OR).
3941

40-
To customize which user can execute the command, update the `ALLOWED_USER_ID` constant in the command's code:
4142

4243
```js
4344
const ALLOWED_USER_ID = "123456789012345678"; // REPLACE WITH YOUR USER ID
45+
const ALLOWED_ROLE_ID = "123456789012345678"; // REPLACE WITH YOUR ROLE ID
4446
```
4547

4648
## 📦 Requirements
@@ -72,7 +74,6 @@ DISCORD_CHANNEL_ID=your-discord-channel-id
7274

7375
```
7476
node index.js
75-
7677
```
7778

7879
## 🚀 Auto-run at Startup (systemd)

src/commands/htop.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ const {
44
ActionRowBuilder,
55
ButtonBuilder,
66
ButtonStyle,
7+
MessageFlags,
78
} = require("discord.js");
89
const si = require("systeminformation");
910

1011
const ALLOWED_USER_ID = "123456789012345678"; // REPLACE WITH YOUR USER ID
12+
const ALLOWED_ROLE_ID = "123456789012345678"; // REPLACE WITH YOUR ROLE ID
13+
1114

1215
function getUniqueProcessesByName(processList) {
1316
const map = new Map();
@@ -62,10 +65,15 @@ module.exports = {
6265
.setDescription("📊 Displays a list of unique processes like `htop`."),
6366

6467
async execute(interaction) {
65-
if (interaction.user.id !== ALLOWED_USER_ID) {
68+
const isAllowedUser = interaction.user.id === ALLOWED_USER_ID;
69+
const hasAllowedRole =
70+
interaction.inGuild() &&
71+
Boolean(interaction.member?.roles?.cache?.has(ALLOWED_ROLE_ID));
72+
73+
if (!isAllowedUser && !hasAllowedRole) {
6674
return interaction.reply({
6775
content: "❌ You do not have permission to use this command.",
68-
ephemeral: true,
76+
flags: MessageFlags.Ephemeral,
6977
});
7078
}
7179

@@ -117,9 +125,9 @@ module.exports = {
117125
await message.edit({ components: [disabledRow] });
118126
});
119127
} catch (err) {
120-
console.error("Błąd komendy /htop:", err);
128+
console.error("Error in /htop command:", err);
121129
await interaction.editReply(
122-
"❌ Wystąpił błąd podczas pobierania procesów."
130+
"❌ An error occurred while fetching processes."
123131
);
124132
}
125133
},

0 commit comments

Comments
 (0)