Skip to content

Commit

Permalink
update to caith 0.2.0 and use the new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Geobert Quach committed Aug 6, 2020
1 parent 949d7c4 commit be28e5d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 0.2.0
- Update to `caith` 0.2.0
- Better error feedback
- Accept uppercase `D`

# 0.1.0
- Initial release
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "disle"
version = "0.1.0"
version = "0.2.0"
authors = ["Geobert Quach <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = { version = "0.2.22", features = ["macros"]}
caith = "0.1.4"
caith = "0.2.0"

[dependencies.serenity]
git = "https://github.com/acdenisSK/serenity"
Expand Down
70 changes: 41 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{collections::HashSet, env};

use serenity::{
client::Context,
framework::{
Expand All @@ -11,7 +13,6 @@ use serenity::{
model::channel::Message,
Client,
};
use std::{collections::HashSet, env};

#[group]
#[commands(roll)]
Expand All @@ -30,41 +31,52 @@ async fn dispatch_error(ctx: &Context, msg: &Message, error: DispatchError) {
}
}

fn get_help_msg() -> String {
r#"```
/roll xdy [OPTIONS]
rolls x dices of y sides
Options:
+ - / * : modifiers
e# : Explode value
ie# : Indefinite explode value
K# : Keeping # highest (upperacse "K")
k# : Keeping # lowest (lowercase "k")
D# : Dropping the highest (uppercase "D")
d# : Dropping the lowest (lowercase "d")
r# : Reroll if <= value
ir# : Indefinite reroll if <= value
t# : Target value to be a success
f# : Value under which it is count as failuer
! : Any text after `!` will be a comment
```"#
.to_string()
}

#[command]
#[help_available]
#[min_args(1)]
#[description("Roll dice(s)")]
async fn roll(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let input = args.rest();
let msg_to_send = if input.trim().starts_with("help") {
r#"```
/roll xdy [OPTIONS]
rolls x dices of y sides
Options:
+ - / * : modifiers
e# : Explode value
ie# : Indefinite explode value
K# : Keeping # highest (upperacse "K")
k# : Keeping # lowest (lowercase "k")
D# : Dropping the highest (uppercase "D")
d# : Dropping the lowest (lowercase "d")
r# : Reroll if <= value
ir# : Indefinite reroll if <= value
t# : Target value to be a success
f# : Value under which it is count as failuer
! : Any text after `!` will be a comment
```"#
.to_string()
let msg_to_send = if input.starts_with("help") {
get_help_msg()
} else {
let res = caith::roll(input)?;
let name = msg
.author
.nick_in(&ctx.http, msg.guild_id.unwrap())
.await
.unwrap_or_else(|| msg.author.name.to_owned());
format!("{} roll: {}", name, res)
match caith::roll(input) {
Ok(res) => {
let name = msg
.author
.nick_in(&ctx.http, msg.guild_id.unwrap())
.await
.unwrap_or_else(|| msg.author.name.to_owned());
format!("{} roll: {}", name, res)
}
Err(err) => match err {
caith::RollError::ParseError(_) => format!("Error:\n```\n{}\n```", err),
caith::RollError::ParamError(err) => format!("Error: {}", err),
},
}
};

if let Err(e) = msg.channel_id.say(&ctx.http, msg_to_send).await {
Expand Down

0 comments on commit be28e5d

Please sign in to comment.