38 lines
826 B
Rust
38 lines
826 B
Rust
use crate::{command, group};
|
|
use reqwest::Client;
|
|
use serde::{Deserialize, Serialize};
|
|
use serenity::client::Context;
|
|
use serenity::framework::standard::{Args, CommandResult};
|
|
use serenity::model::channel::Message;
|
|
|
|
#[derive(Clone, Serialize, Deserialize)]
|
|
struct DadJoke {
|
|
pub id: String,
|
|
pub joke: String,
|
|
pub status: i32,
|
|
}
|
|
|
|
#[group]
|
|
#[commands(dad_joke)]
|
|
pub struct Joke;
|
|
|
|
#[command]
|
|
#[only_in(guilds)]
|
|
#[aliases("dad")]
|
|
#[description("Ask your dad")]
|
|
async fn dad_joke(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
|
let client = Client::new();
|
|
|
|
let joke: DadJoke = client
|
|
.get("https://icanhazdadjoke.com/")
|
|
.header("Accept", "application/json")
|
|
.send()
|
|
.await?
|
|
.json()
|
|
.await?;
|
|
|
|
msg.reply(&ctx.http, joke.joke).await?;
|
|
|
|
Ok(())
|
|
}
|