Skip to content

Commit c550683

Browse files
PeroSarcyberknight777
authored andcommitted
src: List admin commands in /help
Signed-off-by: PeroSar <perosar1111@gmail.com>
1 parent 62333cc commit c550683

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/plugins/dl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! SPDX-License-Identifier: MIT
55
//!
66
7+
// Description: Download a URL or replied Telegram media to the dl/ folder.
8+
79
use grammers_client::{
810
Client,
911
media::Media,

src/plugins/help.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ struct CommandInfo {
1616
description: String,
1717
}
1818

19+
const ADMIN_COMMANDS: &[&str] = &["dl", "mot", "sh", "ul"];
20+
1921
pub async fn knightcmd_help(message: &Message) -> Result<(), Box<dyn std::error::Error>> {
2022
let mut commands = Vec::new();
2123

2224
let plugin_dir = "src/plugins";
2325
for entry in fs::read_dir(plugin_dir)? {
2426
if let Ok(entry) = entry {
2527
if let Some(filename) = entry.file_name().to_str() {
28+
let command_name = filename.trim_end_matches(".rs");
2629
if filename.ends_with(".rs")
2730
&& filename != "mod.rs"
28-
&& filename != "dl.rs"
2931
&& filename != "req.rs"
30-
&& filename != "sh.rs"
31-
&& filename != "mot.rs"
32-
&& filename != "ul.rs"
32+
&& !ADMIN_COMMANDS.contains(&command_name)
3333
{
3434
let command_name = filename.trim_end_matches(".rs").to_string();
3535
let description = get_command_description(&command_name, plugin_dir)?;
@@ -54,6 +54,15 @@ pub async fn knightcmd_help(message: &Message) -> Result<(), Box<dyn std::error:
5454
));
5555
}
5656

57+
help_msg.push_str("\nAdmin commands:\n");
58+
for command in ADMIN_COMMANDS {
59+
help_msg.push_str(&format!(
60+
"k.{name} - {description}\n",
61+
name = command,
62+
description = get_command_description(command, plugin_dir)?
63+
));
64+
}
65+
5766
message.reply(help_msg).await?;
5867

5968
Ok(())

src/plugins/sh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! SPDX-License-Identifier: MIT
55
//!
66
7+
// Description: Execute a shell command.
8+
79
use grammers_client::message::{InputMessage, Message};
810
use std::process::Command;
911

src/plugins/ul.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! SPDX-License-Identifier: MIT
55
//!
66
7+
// Description: Upload a file.
8+
79
use grammers_client::{
810
Client,
911
message::{InputMessage, Message},

0 commit comments

Comments
 (0)