ol_rusty/src/commands/invites.rs

59 lines
1.5 KiB
Rust

use crate::{Context, Error};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Message {
message: String,
}
#[derive(Debug, Deserialize)]
struct InviteData {
// id: String,
// token: String,
// isUsed: bool,
#[serde(rename = "isHighTier")]
is_high_tier: bool,
// isCustom: bool,
}
#[poise::command(slash_command, ephemeral)]
pub async fn invites(
ctx: Context<'_>,
#[description = "The invite to check"] invite: String,
) -> Result<(), Error> {
let client = reqwest::Client::new();
let req = client
.get(format!(
"https://api.morningstreams.com/api/invites/{}",
invite
))
.send()
.await?;
let result = match req.status().as_u16() {
404 | 410 => {
let data: Message = req.json().await?;
format!(
"Invite `{}` is unavailable because: {}",
invite, data.message
)
}
200 => {
let data: InviteData = req.json().await?;
if data.is_high_tier {
format!(
"Invite `{}` is still available and grants High Tier status",
invite
)
} else {
format!("Invite `{}` is still available", invite)
}
}
_ => format!(
"Something unexpected happened with the API, can't check `{}` now",
invite,
),
};
ctx.say(result).await?;
Ok(())
}