LordMZTE
92e452c473
Some checks failed
continuous-integration/drone/push Build is failing
https://tilera.xyz/git/LordMZTE/libjens/
33 lines
899 B
Rust
33 lines
899 B
Rust
use anyhow::bail;
|
|
use libjens::JMClient;
|
|
use tokio::process::Command;
|
|
|
|
pub const NO_SUCH_CATEGORY_ERROR: &str = "The given Category does not exist!";
|
|
pub const NO_SUCH_USER_ERROR: &str = "The given User does not exist!";
|
|
|
|
pub async fn assert_category_exists(client: &JMClient, cat: &str) -> anyhow::Result<()> {
|
|
if !client.get_cats().await?.iter().any(|c| c.id == cat) {
|
|
bail!(NO_SUCH_CATEGORY_ERROR);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn assert_user_exists(client: &JMClient, user: &str) -> anyhow::Result<()> {
|
|
if !client.get_users().await?.iter().any(|u| u.name == user) {
|
|
bail!(NO_SUCH_USER_ERROR);
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub async fn open_link(url: &str) -> anyhow::Result<()> {
|
|
match std::env::var_os("BROWSER") {
|
|
Some(browser) => {
|
|
Command::new(&browser).arg(url).status().await?;
|
|
},
|
|
None => opener::open(&url)?,
|
|
}
|
|
|
|
Ok(())
|
|
}
|