Skip to content

Commit 13a5ef7

Browse files
Merge pull request #26 from jamesbt365/hotfix
Fix various problems and override specific framework errors.
2 parents bebdde4 + eb371a5 commit 13a5ef7

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/commands/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ pub async fn list_repos(ctx: Context<'_>) -> Result<(), Error> {
379379
.map(|token| {
380380
(
381381
token.0.clone(),
382-
format!("{}/{}", token.1.name, token.1.owner),
382+
format!("{}/{}", token.1.owner, token.1.name),
383383
true,
384384
)
385385
})

src/events/issue.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ async fn issue_embeds(data: &Data, message: &Message) -> Option<Vec<CreateEmbed>
107107
let client = octocrab::instance();
108108
let ratelimit = client.ratelimit();
109109

110-
let regex =
111-
Regex::new(r#" ?([a-zA-Z0-9-_.]+)?#([0-9]+[0-9]) ?"#).expect("Expected numbers regex");
110+
let regex = Regex::new(r#" ?([a-zA-Z0-9-_.]+)?#([0-9]+) ?"#).expect("Expected numbers regex");
112111

113112
let custom_repos = { data.state.read().unwrap().issue_prefixes.clone() };
114113

@@ -126,7 +125,9 @@ async fn issue_embeds(data: &Data, message: &Message) -> Option<Vec<CreateEmbed>
126125

127126
issues = client.issues(owner, repo);
128127
prs = client.pulls(owner, repo);
129-
}
128+
} else {
129+
continue; // discards when it doesn't match a repo.
130+
};
130131
}
131132

132133
let ratelimit = ratelimit

src/main.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,38 @@ type Context<'a> = poise::Context<'a, Data, Error>;
2121
async fn on_error(error: poise::FrameworkError<'_, Data, Error>) {
2222
match error {
2323
poise::FrameworkError::Setup { error, .. } => panic!("Failed to start bot: {:?}", error),
24-
poise::FrameworkError::Command { error, ctx, .. } => {
25-
println!("Error in command `{}`: {:?}", ctx.command().name, error,);
24+
poise::FrameworkError::Command { ctx, error, .. } => {
25+
let error = error.to_string();
26+
eprintln!("An error occured in a command: {}", error);
27+
commands::respond_err(&ctx, "Command Error", &error).await;
2628
}
29+
30+
poise::FrameworkError::ArgumentParse {
31+
error, input, ctx, ..
32+
} => {
33+
let usage = match &ctx.command().help_text {
34+
Some(help_text) => &**help_text,
35+
None => "Please check the help menu for usage information",
36+
};
37+
let response = if let Some(input) = input {
38+
format!(
39+
"**Cannot parse `{}` as argument: {}**\n{}",
40+
input, error, usage
41+
)
42+
} else {
43+
format!("### {}\n{}", error, usage)
44+
};
45+
commands::respond_err(&ctx, "Argument Parsing Error", &response).await;
46+
}
47+
poise::FrameworkError::GuildOnly { ctx, .. } => {
48+
commands::respond_err(
49+
&ctx,
50+
"This command cannot be ran in DMs.",
51+
"You cannot run this command in DMs.",
52+
)
53+
.await;
54+
}
55+
2756
error => {
2857
if let Err(e) = poise::builtins::on_error(error).await {
2958
println!("Error while handling error: {}", e)

0 commit comments

Comments
 (0)