aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-01-16 00:02:56 -0500
committerCara Salter <cara@devcara.com>2022-01-16 00:02:56 -0500
commiteb41fede91d072693b279f908976d2ebc2ba1ca3 (patch)
tree81154fe49330b429e66fff098653fc636747717c /src/commands
parent16921c23ff7186381a16ca0b03c521d56ee4eb21 (diff)
downloadglitch-ng-eb41fede91d072693b279f908976d2ebc2ba1ca3.tar.gz
glitch-ng-eb41fede91d072693b279f908976d2ebc2ba1ca3.zip
format
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/actions.rs30
-rw-r--r--src/commands/meta.rs28
-rw-r--r--src/commands/mod.rs4
-rw-r--r--src/commands/osu.rs100
-rw-r--r--src/commands/pony.rs48
5 files changed, 141 insertions, 69 deletions
diff --git a/src/commands/actions.rs b/src/commands/actions.rs
index 96862bb..63d00fb 100644
--- a/src/commands/actions.rs
+++ b/src/commands/actions.rs
@@ -78,11 +78,18 @@ static BOOP_VEC: [&'static str; 15] = [
/// Usage:
/// ~boop <@User>
#[poise::command(context_menu_command = "Boop!", slash_command, prefix_command)]
-pub async fn boop(ctx: Context<'_>,
- #[description = "The user to be booped"] user: serenity::User,
- ) -> Result<(), Error> {
+pub async fn boop(
+ ctx: Context<'_>,
+ #[description = "The user to be booped"] user: serenity::User,
+) -> Result<(), Error> {
let url = get_random_url_from_vec(BOOP_VEC.to_vec());
- ctx.say(format!("<@{}> boops <@{}>! Awwwww!\n{}", ctx.author().id.0, user.id.0, url)).await?;
+ ctx.say(format!(
+ "<@{}> boops <@{}>! Awwwww!\n{}",
+ ctx.author().id.0,
+ user.id.0,
+ url
+ ))
+ .await?;
Ok(())
}
@@ -92,11 +99,18 @@ pub async fn boop(ctx: Context<'_>,
/// Usage:
/// ~hug <@User>
#[poise::command(context_menu_command = "Hug!", slash_command, prefix_command)]
-pub async fn hug(ctx: Context<'_>,
- #[description = "The user to be hugged"] user: serenity::User,
- ) -> Result<(), Error> {
+pub async fn hug(
+ ctx: Context<'_>,
+ #[description = "The user to be hugged"] user: serenity::User,
+) -> Result<(), Error> {
let url = get_random_url_from_vec(HUG_VEC.to_vec());
- ctx.say(format!("<@{}> hugs <@{}>! So kind of them.\n{}", ctx.author().id.0, user.id.0, url)).await?;
+ ctx.say(format!(
+ "<@{}> hugs <@{}>! So kind of them.\n{}",
+ ctx.author().id.0,
+ user.id.0,
+ url
+ ))
+ .await?;
Ok(())
}
diff --git a/src/commands/meta.rs b/src/commands/meta.rs
index d2c5564..917fbfe 100644
--- a/src/commands/meta.rs
+++ b/src/commands/meta.rs
@@ -13,15 +13,18 @@ pub async fn ping(ctx: Context<'_>) -> Result<(), Error> {
#[poise::command(prefix_command, slash_command)]
pub async fn about(ctx: Context<'_>) -> Result<(), Error> {
let current_version = env!("CARGO_PKG_VERSION");
-
- if let Err(e) = ctx.send(|m| {
- m.embed(|e| {
- e.title("Glitch");
- e
- });
- m
- }).await {
+ if let Err(e) = ctx
+ .send(|m| {
+ m.embed(|e| {
+ e.title("Glitch");
+
+ e
+ });
+ m
+ })
+ .await
+ {
return Err(e.into());
}
@@ -29,10 +32,9 @@ pub async fn about(ctx: Context<'_>) -> Result<(), Error> {
}
#[poise::command(prefix_command, slash_command, context_menu_command = "User Info")]
-pub async fn userinfo(ctx: Context<'_>,
- #[description = "The user to get info on"]
- user: serenity::User,
- ) -> Result<(), Error> {
-
+pub async fn userinfo(
+ ctx: Context<'_>,
+ #[description = "The user to get info on"] user: serenity::User,
+) -> Result<(), Error> {
Ok(())
}
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 2121532..3ffb136 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,5 +1,5 @@
-pub mod meta;
-pub mod pony;
pub mod actions;
+pub mod meta;
pub mod osu;
+pub mod pony;
pub mod reactionroles;
diff --git a/src/commands/osu.rs b/src/commands/osu.rs
index 28d3cb3..8d91f56 100644
--- a/src/commands/osu.rs
+++ b/src/commands/osu.rs
@@ -29,17 +29,24 @@ async fn setup_reqwest() -> Result<reqwest::Client, Error> {
scope: "public".into(),
};
- let req = reqwest::Client::new().post("https://osu.ppy.sh/oauth/token")
- .json(&token_req).send().await?
- .json::<OsuTokenResponse>().await?;
-
+ let req = reqwest::Client::new()
+ .post("https://osu.ppy.sh/oauth/token")
+ .json(&token_req)
+ .send()
+ .await?
+ .json::<OsuTokenResponse>()
+ .await?;
let mut headers = header::HeaderMap::new();
- headers.insert("Authorization", header::HeaderValue::from_str(format!("Bearer {}", req.access_token).as_str()).unwrap());
-
+ headers.insert(
+ "Authorization",
+ header::HeaderValue::from_str(format!("Bearer {}", req.access_token).as_str()).unwrap(),
+ );
+
Ok(ClientBuilder::new()
.default_headers(headers)
- .build().unwrap())
+ .build()
+ .unwrap())
}
#[derive(Deserialize, Serialize, Clone, Debug)]
@@ -75,14 +82,21 @@ struct OsuUserStatsGrades {
/// Examples:
/// ~osup muirrum
#[poise::command(slash_command, prefix_command)]
-pub async fn osup(ctx: Context<'_>,
- #[description = "The osu! username or ID to look up"]
- lookup: String,
- ) -> Result<(), Error> {
+pub async fn osup(
+ ctx: Context<'_>,
+ #[description = "The osu! username or ID to look up"] lookup: String,
+) -> Result<(), Error> {
let client = setup_reqwest().await?;
- let mut res = client.get(format!("https://osu.ppy.sh/api/v2/users/{}?key=username", lookup))
- .send().await?.json::<OsuUser>().await?;
+ let mut res = client
+ .get(format!(
+ "https://osu.ppy.sh/api/v2/users/{}?key=username",
+ lookup
+ ))
+ .send()
+ .await?
+ .json::<OsuUser>()
+ .await?;
res.country_code = res.country_code.to_lowercase();
@@ -90,13 +104,31 @@ pub async fn osup(ctx: Context<'_>,
m.embed(|e| {
e.title(format!("osu! Profile: {}", res.clone().username));
e.thumbnail(res.clone().avatar_url);
- e.field("Ranks", format!(":map: #{}\n:flag_{}: #{}", res.clone().statistics.global_rank.unwrap_or(0), res.clone().country_code, res.clone().statistics.country_rank.unwrap_or(0u32)), true);
-
- e.field("Stats", format!("**PP:** {}\n**Acc:** {}%", res.clone().statistics.pp, res.clone().statistics.hit_accuracy.unwrap_or(0.0)), false);
+ e.field(
+ "Ranks",
+ format!(
+ ":map: #{}\n:flag_{}: #{}",
+ res.clone().statistics.global_rank.unwrap_or(0),
+ res.clone().country_code,
+ res.clone().statistics.country_rank.unwrap_or(0u32)
+ ),
+ true,
+ );
+
+ e.field(
+ "Stats",
+ format!(
+ "**PP:** {}\n**Acc:** {}%",
+ res.clone().statistics.pp,
+ res.clone().statistics.hit_accuracy.unwrap_or(0.0)
+ ),
+ false,
+ );
e
});
m
- }).await?;
+ })
+ .await?;
Ok(())
}
@@ -140,28 +172,42 @@ struct OsuBeatMapSetCovers {
/// Usage:
/// ~osubm <id>
#[poise::command(slash_command, prefix_command)]
-pub async fn osubm(ctx: Context<'_>,
- #[description = "The beatmap ID"]
- bm_id: u32,
- ) -> Result<(), Error> {
+pub async fn osubm(
+ ctx: Context<'_>,
+ #[description = "The beatmap ID"] bm_id: u32,
+) -> Result<(), Error> {
let client = setup_reqwest().await?;
- let mut res = client.get(format!("https://osu.ppy.sh/api/v2/beatmaps/{}", bm_id))
- .send().await?.json::<OsuBeatMap>().await?;
+ let mut res = client
+ .get(format!("https://osu.ppy.sh/api/v2/beatmaps/{}", bm_id))
+ .send()
+ .await?
+ .json::<OsuBeatMap>()
+ .await?;
ctx.send(|m| {
m.embed(|e| {
- e.title(format!("osu! Beatmap: {} by {}", res.beatmapset.title, res.beatmapset.creator));
+ e.title(format!(
+ "osu! Beatmap: {} by {}",
+ res.beatmapset.title, res.beatmapset.creator
+ ));
e.image(res.beatmapset.covers.list2);
- e.description(format!("**Link:** {}\n**Length:** {} **BPM:** {}\n**Difficulty:** {}:star:", res.url, res.total_length, res.bpm, res.difficulty_rating));
+ e.description(format!(
+ "**Link:** {}\n**Length:** {} **BPM:** {}\n**Difficulty:** {}:star:",
+ res.url, res.total_length, res.bpm, res.difficulty_rating
+ ));
e.footer(|f| {
- f.text(format!("BM ID {} | BM Set ID {}\nCreated {}", res.id, res.beatmapset.id, res.beatmapset.submitted_date));
+ f.text(format!(
+ "BM ID {} | BM Set ID {}\nCreated {}",
+ res.id, res.beatmapset.id, res.beatmapset.submitted_date
+ ));
f
});
e
});
m
- }).await?;
+ })
+ .await?;
Ok(())
}
diff --git a/src/commands/pony.rs b/src/commands/pony.rs
index 75b4238..b908ca4 100644
--- a/src/commands/pony.rs
+++ b/src/commands/pony.rs
@@ -39,8 +39,10 @@ pub struct PonyRepresentation {
/// Retrieves a random SFW pony image
#[poise::command(slash_command, prefix_command)]
pub async fn randpony(ctx: Context<'_>) -> Result<(), Error> {
- let mut response_msg = ctx.say("Fetching a random pony image, please wait!").await?;
-
+ let mut response_msg = ctx
+ .say("Fetching a random pony image, please wait!")
+ .await?;
+
let client = reqwest::Client::new();
let res = reqwest::get("https://theponyapi.com/api/v1/pony/random")
.await?
@@ -65,11 +67,12 @@ pub async fn randpony(ctx: Context<'_>) -> Result<(), Error> {
e
});
m
- }).await?;
- },
+ })
+ .await?;
+ }
Err(e) => {
ctx.say("Error editing message").await?;
- },
+ }
};
Ok(())
@@ -82,18 +85,25 @@ pub async fn randpony(ctx: Context<'_>) -> Result<(), Error> {
/// Example:
/// ~tpony twilight sparkle,fluttershy
#[poise::command(slash_command, prefix_command)]
-pub async fn tpony(ctx: Context<'_>,
- #[description = "List of tags"]
- #[rest]
- tags: String,
- ) -> Result<(), Error> {
- let mut response_msg = ctx.say(format!("Fetching pony image based on tags: {:?}", tags.clone())).await?;
-
- let res = reqwest::get(format!("https://theponyapi.com/api/v1/pony/random?q={}", tags).as_str())
- .await?
- .json::<PonyResponse>()
+pub async fn tpony(
+ ctx: Context<'_>,
+ #[description = "List of tags"]
+ #[rest]
+ tags: String,
+) -> Result<(), Error> {
+ let mut response_msg = ctx
+ .say(format!(
+ "Fetching pony image based on tags: {:?}",
+ tags.clone()
+ ))
.await?;
+ let res =
+ reqwest::get(format!("https://theponyapi.com/api/v1/pony/random?q={}", tags).as_str())
+ .await?
+ .json::<PonyResponse>()
+ .await?;
+
match response_msg.unwrap().message().await {
Ok(mut msg) => {
msg.edit(&ctx.discord(), |m| {
@@ -112,14 +122,14 @@ pub async fn tpony(ctx: Context<'_>,
e
});
m
- }).await?;
- },
+ })
+ .await?;
+ }
Err(e) => {
ctx.say("Error editing message").await?;
- },
+ }
};
-
Ok(())
}