Add inspirobot command
Signed-off-by: trivernis <trivernis@protonmail.com>pull/36/head
parent
c8be3949df
commit
0ddee0f179
@ -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(())
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue