moover_rust/src/util/gifs.rs

9 lines
378 B
Rust
Raw Normal View History

2024-10-06 14:53:12 +00:00
use tenorv2::{tenor, tenor_types::{MediaFilter, TenorError}, JsonValue};
pub async fn get_random_tenor_gif(tenor_response: JsonValue, limit: u8) -> Result<String, TenorError> {
let index = rand::random::<usize>() % limit as usize;
match tenor::get_gif_url(MediaFilter::gif, tenor_response) {
Ok(urls) => Ok(urls[index].clone()),
Err(e) => Err(e)
}
}