Browse Source

Fix formatting

master
Stephen 1 month ago
parent
commit
a96334b085
3 changed files with 21 additions and 10 deletions
  1. +7
    -3
      src/handler.rs
  2. +13
    -6
      src/joker.rs
  3. +1
    -1
      src/main.rs

+ 7
- 3
src/handler.rs View File

@ -1,6 +1,6 @@
use crate::framebuffer::FrameBuffer;
use crate::program::Program;
use crate::joker::tell_joke;
use crate::program::Program;
use diesel::PgConnection;
use phf::phf_map;
use serenity::async_trait;
@ -188,9 +188,13 @@ impl Handler {
"!JOKE" => {
match tell_joke().await {
Some(s) => msg.channel_id.say(&ctx, s).await.unwrap(),
None => msg.channel_id.say(&ctx, "There was an error while fetching a joke.").await.unwrap()
None => msg
.channel_id
.say(&ctx, "There was an error while fetching a joke.")
.await
.unwrap(),
};
}, // FIXME
} // FIXME
_ => {}
}
}


+ 13
- 6
src/joker.rs View File

@ -1,13 +1,20 @@
use serde_json::Value;
pub async fn tell_joke() -> Option<String> {
let joke: Value = reqwest::get("https://v2.jokeapi.dev/joke/Programming").await.ok()?.json().await.ok()?;
let joke: Value = reqwest::get("https://v2.jokeapi.dev/joke/Programming")
.await
.ok()?
.json()
.await
.ok()?;
match joke["type"].as_str()? {
"single" => {
Some(joke["joke"].as_str()?.to_owned())
},
"twopart" => Some(format!("{}\r\n\r\n{}", joke["setup"].as_str()?, joke["delivery"].as_str()?)),
_ => None
"single" => Some(joke["joke"].as_str()?.to_owned()),
"twopart" => Some(format!(
"{}\r\n\r\n{}",
joke["setup"].as_str()?,
joke["delivery"].as_str()?
)),
_ => None,
}
}

+ 1
- 1
src/main.rs View File

@ -4,10 +4,10 @@ extern crate diesel;
mod config;
mod framebuffer;
mod handler;
mod joker;
mod models;
mod program;
mod schema;
mod joker;
use crate::handler::Handler;
use diesel::{Connection, PgConnection};


Loading…
Cancel
Save