Added ability to pick albums for motivation
+ clippy + fmt
This commit is contained in:
parent
295f2704bc
commit
8ec84ff946
@ -59,13 +59,23 @@ pub async fn create_motivation_image(motivation: Motivation) -> Result<Vec<u8>,
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
#[description("Let's give you motivation")]
|
#[description("Let's give you motivation")]
|
||||||
async fn motivation(ctx: &Context, msg: &Message, _args: Args) -> CommandResult {
|
async fn motivation(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.read().await;
|
||||||
let global_data = data.get::<GlobalData>().unwrap();
|
let global_data = data.get::<GlobalData>().unwrap();
|
||||||
|
|
||||||
let motivation =
|
let album_name = if args.is_empty() {
|
||||||
MotivationConfig::generate_motivation(&global_data.db, &global_data.cfg.img_path, "white")
|
None
|
||||||
.await?;
|
} else {
|
||||||
|
Some(args.parse::<String>()?)
|
||||||
|
};
|
||||||
|
|
||||||
|
let motivation = MotivationConfig::generate_motivation(
|
||||||
|
&global_data.db,
|
||||||
|
&global_data.cfg.img_path,
|
||||||
|
"white",
|
||||||
|
album_name,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let image = create_motivation_image(motivation).await?;
|
let image = create_motivation_image(motivation).await?;
|
||||||
|
|
||||||
|
|||||||
@ -322,6 +322,7 @@ pub async fn restock_shop(ctx: &Context) -> Result<(), CommandError> {
|
|||||||
&global_data.db,
|
&global_data.db,
|
||||||
&global_data.cfg.img_path,
|
&global_data.cfg.img_path,
|
||||||
"gold",
|
"gold",
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::album_manager::Album;
|
use crate::album_manager::Album;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use j_db::database::Database;
|
use j_db::database::Database;
|
||||||
|
use j_db::error::JDbError;
|
||||||
use j_db::model::JdbModel;
|
use j_db::model::JdbModel;
|
||||||
use rand::prelude::{IteratorRandom, SliceRandom};
|
use rand::prelude::{IteratorRandom, SliceRandom};
|
||||||
use rand::thread_rng;
|
use rand::thread_rng;
|
||||||
@ -80,17 +81,28 @@ impl MotivationConfig {
|
|||||||
db: &Database,
|
db: &Database,
|
||||||
base_path: &Path,
|
base_path: &Path,
|
||||||
border_color: &str,
|
border_color: &str,
|
||||||
|
album_name: Option<String>,
|
||||||
) -> Result<Motivation, Error> {
|
) -> Result<Motivation, Error> {
|
||||||
let motivation = Self::get_motivation_config(db)?;
|
let motivation = Self::get_motivation_config(db)?;
|
||||||
|
|
||||||
let mut images = Vec::new();
|
let mut images = Vec::new();
|
||||||
|
|
||||||
for album in motivation.album {
|
if let Some(album_name) = album_name {
|
||||||
let album = db.get::<Album>(album);
|
let album = Album::find_album_by_name_or_alias(db, &album_name)?;
|
||||||
|
|
||||||
if let Ok(album) = album {
|
if let Some(mut album) = album {
|
||||||
let mut album_images = album.images.clone();
|
images.append(&mut album.images)
|
||||||
images.append(&mut album_images);
|
} else {
|
||||||
|
return Err(Error::from(JDbError::NotFound));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for album in motivation.album {
|
||||||
|
let album = db.get::<Album>(album);
|
||||||
|
|
||||||
|
if let Ok(album) = album {
|
||||||
|
let mut album_images = album.images.clone();
|
||||||
|
images.append(&mut album_images);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user