diff options
Diffstat (limited to 'src/commands/game.rs')
| -rw-r--r-- | src/commands/game.rs | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/commands/game.rs b/src/commands/game.rs index 72633b5..3b16fd3 100644 --- a/src/commands/game.rs +++ b/src/commands/game.rs @@ -9,7 +9,10 @@ use std::{ }, }; -use anyhow::anyhow; +use anyhow::{ + anyhow, + Context, +}; use fnv::{ FnvHashMap, FnvHashSet, @@ -64,7 +67,7 @@ struct ProfileInfo { lazy_static! { static ref USER_MAP_STR: String = { - let default_path = PathBuf::from_str("user_id_mapping").unwrap(); + let default_path = PathBuf::from_str("user_id_mapping.json").unwrap(); let mapping_path = CONFIG.user_id_mapping.as_ref().unwrap_or(&default_path); fs::read_to_string(mapping_path).unwrap_or("{}".to_owned()) @@ -143,11 +146,17 @@ pub fn commands() -> Vec<poise::Command<crate::PoiseData, anyhow::Error>> { vec![installedgame(), ownedgame(), game(), updategaem()] } +/// Find a game everyone can play (marked installed). +/// +/// Looks up users in the general voice channel if no users are passed. #[poise::command(prefix_command, guild_only, category = "gaem", aliases("installedgaem"))] pub async fn installedgame(ctx: PoiseContext<'_>, args: util::RestVec) -> anyhow::Result<()> { _game(ctx, args.into_inner(), GameStatus::Installed).await } +/// Find a game everyone owns. +/// +/// Looks up users in the general voice channel if no users are passed. #[poise::command(prefix_command, guild_only, category = "gaem", aliases("ownedgaem"))] pub async fn ownedgame(ctx: PoiseContext<'_>, args: util::RestVec) -> anyhow::Result<()> { _game(ctx, args.into_inner(), GameStatus::NotInstalled).await @@ -202,8 +211,14 @@ pub fn get_user_id<S: AsRef<str>>(g: &Guild, s: S) -> StdResult<UserId, UserLook } } +/// Find a game everyone can play (marked installed). +/// +/// Looks up users in the general voice channel if no users are passed. #[poise::command(prefix_command, guild_only, category = "gaem", aliases("gaem"))] -async fn game(ctx: PoiseContext<'_>, args: util::RestVec) -> anyhow::Result<()> { +async fn game( + ctx: PoiseContext<'_>, + #[description = "other users to include"] args: util::RestVec, +) -> anyhow::Result<()> { _game(ctx, args.into_inner(), GameStatus::Installed).await } @@ -417,13 +432,8 @@ async fn load_spreadsheet(client: &reqwest::Client) -> Result<Vec<Vec<String>>> Ok(resp.value_ranges.into_iter().next().unwrap().values) } -#[poise::command( - slash_command, - prefix_command, - guild_only, - category = "gaem", - aliases("updategame") -)] +/// Find games that are out-of-date on the spreadsheet. +#[poise::command(prefix_command, guild_only, category = "gaem", aliases("updategame"))] pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow::Result<()> { use regex::Regex; use std::borrow::Borrow; @@ -537,13 +547,16 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow:: .get(u) .send() .await? + .error_for_status() + .context("retrieve steam info http status")? .json::<SteamResp>() - .await? - .response - .games - .into_iter() - .map(|ge| ge.app_id) - .collect::<FnvHashSet<_>>(); + .await + .context("decode steam resp")?; + + let games_owned = + games_owned.response.games.into_iter().map(|ge| ge.app_id).collect::<FnvHashSet<_>>(); + + debug!("user owns {} steam games", games_owned.len()); let found_games = missing_appids .filter_map(|(ai, x)| { @@ -560,7 +573,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option<String>) -> anyhow:: util::reply( ctx, format!( - "{n_missing} games owned on steam that are missing from the list:\n{found_games}" + "{n_missing} games owned on steam that aren't marked on the list:\n{found_games}" ), ) .await?; |
