Skip to content

Commit 670c4ba

Browse files
committed
changed command structure
1 parent c78d4a0 commit 670c4ba

8 files changed

Lines changed: 48 additions & 23 deletions

File tree

src/bin/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ async fn main() -> Result<(), Box<Error>> {
2727
register(),
2828
commands::help(),
2929
commands::cargo(),
30-
commands::run_alias(),
30+
commands::run_code_block(),
31+
commands::miri_code_block(),
32+
commands::publish(),
3133
commands::explain(),
3234
commands::reload_errors(),
3335
commands::krate(),

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod explain;
44
mod help;
55
mod krate;
66

7-
pub use cargo::{cargo, run_alias};
7+
pub use cargo::{cargo, miri_code_block, publish, run_code_block};
88
pub use docs::docs;
99
pub use explain::{explain, reload_errors};
1010
pub use help::help;

src/commands/cargo.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ use common::{Output, WithCode};
1515
use crates::crates;
1616
use file::file;
1717
use gist::gist;
18-
use miri::miri;
18+
pub use miri::miri_code_block;
1919
use poise::command;
20-
use publish::publish;
20+
pub use publish::publish;
2121
use response::BotResponse;
22-
pub use run::run_alias;
23-
use run::run_code_block;
22+
pub use run::run_code_block;
2423
use version::version;
2524

2625
#[command(
2726
prefix_command,
2827
slash_command,
29-
subcommands("run_code_block", "publish", "miri", "crates", "version")
28+
subcommands("crates", "version"),
29+
category = "cargo"
3030
)]
3131
pub async fn cargo(_ctx: Context<'_>) -> Result<(), Error> {
3232
Ok(())

src/commands/cargo/crates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{Context, Error};
22
use poise::{CreateReply, serenity_prelude::CreateEmbed};
33

44
/// List the crates available to use in the rust playground
5-
#[poise::command(slash_command)]
5+
#[poise::command(slash_command, category = "cargo")]
66
pub async fn crates(
77
ctx: Context<'_>,
88
#[description = "Which page (24 per page)?"] page: Option<usize>,

src/commands/cargo/miri.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,25 @@ const MIRI_RES: MiriResponse = MiriResponse {
1010
exit_detail: Cow::Borrowed(""),
1111
};
1212

13-
#[poise::command(prefix_command, slash_command, subcommands("miri_gist", "miri_file"))]
14-
pub async fn miri(ctx: Context<'_>, #[rest] input: String) -> Result<(), Error> {
13+
#[poise::command(
14+
prefix_command,
15+
slash_command,
16+
rename = "miri",
17+
subcommands("miri_gist", "miri_file"),
18+
category = "cargo",
19+
broadcast_typing
20+
)]
21+
pub async fn miri_code_block(ctx: Context<'_>, #[rest] input: String) -> Result<(), Error> {
1522
super::code_block(ctx, &input, parse_miri, MIRI_RES, "miri").await
1623
}
1724

1825
/// Runs code from a Github gist using miri
19-
#[poise::command(slash_command, rename = "gist", member_cooldown = 60)]
26+
#[poise::command(
27+
slash_command,
28+
rename = "gist",
29+
member_cooldown = 60,
30+
category = "cargo"
31+
)]
2032
#[allow(clippy::too_many_arguments)]
2133
async fn miri_gist(
2234
ctx: Context<'_>,
@@ -38,7 +50,12 @@ async fn miri_gist(
3850
}
3951

4052
/// Run code from a rust file using miri
41-
#[poise::command(slash_command, rename = "file", member_cooldown = 60)]
53+
#[poise::command(
54+
slash_command,
55+
rename = "file",
56+
member_cooldown = 60,
57+
category = "cargo"
58+
)]
4259
#[allow(clippy::too_many_arguments)]
4360
async fn miri_file(
4461
ctx: Context<'_>,

src/commands/cargo/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use poise::{CreateReply, command};
44
use std::borrow::Cow;
55

66
/// Publish code in a code block to GitHub Gists
7-
#[command(prefix_command, guild_cooldown = 60)]
7+
#[command(prefix_command, guild_cooldown = 60, category = "cargo")]
88
pub async fn publish(ctx: Context<'_>, #[rest] input: Option<String>) -> Result<(), Error> {
99
let input = input.unwrap_or("".to_owned());
1010
let (_, code) = crate::common::extract_before_and_code(&input)?;

src/commands/cargo/run.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ const EXECUTE_RES: ExecuteResponse = ExecuteResponse {
1717
prefix_command,
1818
slash_command,
1919
rename = "run",
20-
subcommands("run_gist", "run_file")
20+
subcommands("run_gist", "run_file"),
21+
category = "cargo",
22+
broadcast_typing
2123
)]
2224
pub async fn run_code_block(ctx: Context<'_>, #[rest] input: String) -> Result<(), Error> {
2325
super::code_block(ctx, &input, parse_run_command, EXECUTE_RES, "run").await
2426
}
2527

26-
/// Runs code from a code block in the Rust playground and returns the output
27-
#[poise::command(prefix_command, rename = "run")]
28-
pub async fn run_alias(ctx: Context<'_>, #[rest] input: String) -> Result<(), Error> {
29-
super::code_block(ctx, &input, parse_run_command, EXECUTE_RES, "run").await
30-
}
31-
3228
/// Runs code from a Github gist
33-
#[poise::command(slash_command, rename = "gist", member_cooldown = 60)]
29+
#[poise::command(
30+
slash_command,
31+
rename = "gist",
32+
member_cooldown = 60,
33+
category = "cargo"
34+
)]
3435
#[allow(clippy::too_many_arguments)]
3536
async fn run_gist(
3637
ctx: Context<'_>,
@@ -58,7 +59,12 @@ async fn run_gist(
5859
}
5960

6061
/// Runs code from a Rust source file upload
61-
#[poise::command(slash_command, rename = "file", member_cooldown = 60)]
62+
#[poise::command(
63+
slash_command,
64+
rename = "file",
65+
member_cooldown = 60,
66+
category = "cargo"
67+
)]
6268
#[allow(clippy::too_many_arguments)]
6369
async fn run_file(
6470
ctx: Context<'_>,

src/commands/cargo/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use poise::{
66
};
77

88
/// Get the current `rustc`, `clippy`, `rustfmt` and `miri` versions used when running `!cargo run`
9-
#[command(slash_command, prefix_command)]
9+
#[command(slash_command, prefix_command, category = "cargo")]
1010
pub async fn version(ctx: Context<'_>, channel: Channel) -> Result<(), Error> {
1111
let res = if let Some(content) = ctx.data().redis_client.get("version").await? {
1212
content

0 commit comments

Comments
 (0)