Add inspirobot command

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/36/head
trivernis 3 years ago
parent c8be3949df
commit 0ddee0f179
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

2
Cargo.lock generated

@ -2575,7 +2575,7 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tobi-rs"
version = "0.9.2"
version = "0.9.3"
dependencies = [
"animethemes-rs",
"aspotify",

@ -1,6 +1,6 @@
[package]
name = "tobi-rs"
version = "0.9.2"
version = "0.9.3"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"

@ -0,0 +1,16 @@
use crate::messages::inspirobot::create_inspirobot_menu;
use serenity::client::Context;
use serenity::framework::standard::macros::command;
use serenity::framework::standard::CommandResult;
use serenity::model::channel::Message;
#[command]
#[description("Get an inspiring quote")]
#[usage("")]
#[aliases("inspireme", "inspire-me", "inspiro")]
#[bucket("general")]
async fn inspirobot(ctx: &Context, msg: &Message) -> CommandResult {
create_inspirobot_menu(ctx, msg.channel_id).await?;
Ok(())
}

@ -4,6 +4,7 @@ use about::ABOUT_COMMAND;
use add_media::ADD_MEDIA_COMMAND;
use clear::CLEAR_COMMAND;
use fuck::FUCK_COMMAND;
use inspirobot::INSPIROBOT_COMMAND;
use media::MEDIA_COMMAND;
use pain::PAIN_COMMAND;
use party::PARTY_COMMAND;
@ -20,6 +21,7 @@ mod add_media;
mod clear;
mod fuck;
pub(crate) mod help;
mod inspirobot;
mod media;
mod pain;
mod party;
@ -34,6 +36,6 @@ mod xkcd;
#[group]
#[commands(
ping, stats, shutdown, time, timezones, qalc, about, add_media, media, pain, clear, xkcd, fuck,
party
party, inspirobot
)]
pub struct Misc;

@ -0,0 +1,42 @@
use crate::providers::music::inspirobot::get_inspirobot_image;
use crate::utils::error::BotResult;
use serenity::builder::CreateMessage;
use serenity::client::Context;
use serenity::model::id::ChannelId;
use serenity_rich_interaction::core::EXTRA_LONG_TIMEOUT;
use serenity_rich_interaction::menu::{display_page, MenuBuilder, Page};
static REFRESH_CONTROL: &str = "🔄";
pub async fn create_inspirobot_menu(ctx: &Context, channel_id: ChannelId) -> BotResult<()> {
MenuBuilder::default()
.add_control(0, REFRESH_CONTROL, |ctx, menu, _r| {
Box::pin(async move {
display_page(ctx, menu).await?;
Ok(())
})
})
.add_help(REFRESH_CONTROL, "Creates a new inspiring image.")
.show_help()
.add_page(Page::new_builder(|| {
Box::pin(async {
let message = create_inspirobot_page()
.await
.map_err(|e| serenity_rich_interaction::Error::Msg(format!("{}", e)))?;
Ok(message)
})
}))
.timeout(EXTRA_LONG_TIMEOUT)
.build(ctx, channel_id)
.await?;
Ok(())
}
async fn create_inspirobot_page<'a>() -> BotResult<CreateMessage<'a>> {
let image = get_inspirobot_image().await?;
let mut message = CreateMessage::default();
message.embed(|e| e.image(image).title("Be inspired"));
Ok(message)
}

@ -10,6 +10,7 @@ pub mod music;
pub mod sauce;
pub mod theme;
pub mod xkcd;
pub mod inspirobot;
/// Adds an ephemeral message to the database
pub async fn add_ephemeral_handle_to_database(

@ -0,0 +1,10 @@
use crate::utils::error::BotResult;
static INSPIROBOT_ENDPOINT: &str = "https://inspirobot.me/api?generate=true";
pub async fn get_inspirobot_image() -> BotResult<String> {
let response = reqwest::get(INSPIROBOT_ENDPOINT).await?;
let url = response.text().await?;
Ok(url)
}

@ -7,6 +7,7 @@ use regex::Regex;
use responses::VideoInformation;
use youtube_dl::search_video_information;
pub mod inspirobot;
pub mod lavalink;
pub mod lyrics;
pub mod player;

Loading…
Cancel
Save