Skip to content

Commit

Permalink
feat: add support for 204 No Content response to the BL client
Browse files Browse the repository at this point in the history
  • Loading branch information
motzel committed Mar 12, 2024
1 parent f7f671a commit 0d4a327
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/beatleader/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::beatleader::oauth::OAuthErrorResponse;
use chrono::{DateTime, Utc};
use std::{error, fmt};

use chrono::{DateTime, Utc};

use crate::beatleader::oauth::OAuthErrorResponse;

#[derive(Debug)]
pub enum Error {
Request(reqwest::Error),
Network(reqwest::Error),
NotFound,
NoContent,
Unauthorized,
Client(Option<String>),
OAuth(Option<OAuthErrorResponse>),
Expand All @@ -23,7 +26,8 @@ impl fmt::Display for Error {
match self {
Error::Request(e) => write!(f, "BL request building error: {}", e),
Error::Network(e) => write!(f, "network error ({})", e),
Error::NotFound => write!(f, "BL player not found"),
Error::NoContent => write!(f, "no content"),
Error::NotFound => write!(f, "not found"),
Error::Unauthorized => write!(f, "BL unauthorized error"),
Error::Client(_) => write!(f, "BL client error"),
Error::Server => write!(f, "BL server error"),
Expand Down Expand Up @@ -51,6 +55,7 @@ impl error::Error for Error {
Error::Request(e) | Error::Network(e) => Some(e),
Error::JsonDecode(e) => Some(e),
Error::NotFound
| Error::NoContent
| Error::Unauthorized
| Error::Client(_)
| Error::Server
Expand Down
9 changes: 5 additions & 4 deletions src/beatleader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::future::Future;
use std::num::NonZeroU32;
use std::result;
use std::time::Duration;

use governor::clock::DefaultClock;
Expand All @@ -10,14 +12,12 @@ use reqwest::{
Url,
};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use tracing::{debug, error, info, trace};

use crate::beatleader::clan::ClanResource;
use player::PlayerResource;
use serde::{Deserialize, Serialize};
use std::future::Future;
use std::result;

use crate::beatleader::clan::ClanResource;
use crate::beatleader::error::Error;
use crate::beatleader::oauth::{ClientWithOAuth, OAuthAppCredentials, OAuthTokenRepository};
use crate::beatleader::rating::AiRatingsResource;
Expand Down Expand Up @@ -175,6 +175,7 @@ impl Client {
);

match response.status().as_u16() {
204 => Err(Error::NoContent),
200..=299 => Ok(response),
401 | 403 => Err(Error::Unauthorized),
404 => Err(Error::NotFound),
Expand Down
8 changes: 4 additions & 4 deletions src/discord/bot/beatleader/clan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ use std::sync::Arc;
use chrono::{DateTime, Duration, Utc};
use serde::{Deserialize, Serialize};

use crate::{beatleader, BL_CLIENT};
use crate::beatleader::{BlContext, DataWithMeta, SortOrder};
use crate::beatleader::clan::{
Clan, ClanId, ClanMap, ClanMapParam, ClanMapScore, ClanMapsParam, ClanMapsSort, ClanTag,
};
use crate::beatleader::error::Error as BlError;
use crate::beatleader::player::{Difficulty, PlayerId};
use crate::beatleader::pp::{
calculate_acc_from_pp, calculate_pp_boundary, CLAN_WEIGHT_COEFFICIENT, StarRating,
calculate_acc_from_pp, calculate_pp_boundary, StarRating, CLAN_WEIGHT_COEFFICIENT,
};
use crate::beatleader::{BlContext, DataWithMeta, SortOrder};
use crate::discord::bot::beatleader::player::Player;
use crate::discord::bot::beatleader::score::{MapRatingModifier, MapRatings};
use crate::storage::{StorageKey, StorageValue};
use crate::storage::player_scores::PlayerScoresRepository;
use crate::storage::{StorageKey, StorageValue};
use crate::{beatleader, BL_CLIENT};

#[derive(
Debug, poise::ChoiceParameter, Serialize, Deserialize, Clone, Default, Hash, PartialEq, Eq,
Expand Down
18 changes: 9 additions & 9 deletions src/discord/bot/commands/clan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ use std::borrow::Cow;
use std::cmp::Ordering;
use std::sync::Arc;

use magic_crypt::{MagicCryptTrait, new_magic_crypt};
use poise::CreateReply;
use magic_crypt::{new_magic_crypt, MagicCryptTrait};
use poise::serenity_prelude::{ChannelId, CreateAttachment, Message, Permissions, Role, User};
use poise::CreateReply;

use crate::{BL_CLIENT, Error};
use crate::beatleader::clan::Clan;
use crate::beatleader::clan::ClanMapParam;
use crate::beatleader::clan::ClanRankingParam;
use crate::beatleader::DataWithMeta;
use crate::beatleader::oauth::{OAuthScope, OAuthTokenRepository};
use crate::beatleader::pp::calculate_total_pp_from_sorted;
use crate::beatleader::pp::CLAN_WEIGHT_COEFFICIENT;
use crate::discord::bot::{ClanSettings, GuildOAuthTokenRepository};
use crate::beatleader::DataWithMeta;
use crate::discord::bot::beatleader::clan::{
AccBoundary, ClanMapWithScores, ClanWarsFc, ClanWarsPlayDate, ClanWarsSort, fetch_clan,
fetch_clan, AccBoundary, ClanMapWithScores, ClanWarsFc, ClanWarsPlayDate, ClanWarsSort,
Playlist,
};
use crate::discord::bot::beatleader::player::fetch_player_from_bl;
use crate::discord::bot::commands::{
get_leaderboard_ids_from_message, get_user_id_with_required_permission,
};
use crate::discord::bot::commands::guild::{get_guild_id, get_guild_settings};
use crate::discord::bot::commands::player::{
link_user_if_needed, say_profile_not_linked, say_without_ping,
};
use crate::discord::bot::commands::{
get_leaderboard_ids_from_message, get_user_id_with_required_permission,
};
use crate::discord::bot::{ClanSettings, GuildOAuthTokenRepository};
use crate::discord::Context;
use crate::{Error, BL_CLIENT};

/// Set up sending of clan invitations
#[tracing::instrument(skip(ctx), level=tracing::Level::INFO, name="bot_command:bl-set-clan-invitation")]
Expand Down

0 comments on commit 0d4a327

Please sign in to comment.