Skip to content

Commit

Permalink
more renames
Browse files Browse the repository at this point in the history
  • Loading branch information
B-2U committed Aug 14, 2024
1 parent 6c9d6ee commit 71cdfd8
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/cmds/recent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use poise::{
use crate::{
dc_utils::{autocomplete, Args, ContextAddon, UserAddon},
structs::{
AutoCompletePlayer, Mode, PartialPlayer, Player, PlayerSnapshots, PlayerSnapshotsType,
AutocompletePlayer, Mode, PartialPlayer, Player, PlayerSnapshots, PlayerSnapshotsType,
Ship, ShipId, ShipModeStatsPair, ShipStatsCollection,
},
template_data::{
Expand Down Expand Up @@ -41,7 +41,7 @@ pub async fn recent(
#[description = "last 1~30 (90 for patreons) days of stats, default: 1"] days: Option<u64>,
#[description = "player's ign, default: yourself"]
#[autocomplete = "autocomplete::player"]
player: Option<AutoCompletePlayer>, // the String is a Serialized PartialPlayer struct
player: Option<AutocompletePlayer>, // the String is a Serialized PartialPlayer struct
#[description = "@ping / discord user's ID, default: yourself"]
#[rename = "user"]
discord_user: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/setting.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
dc_utils::{autocomplete, UserAddon},
structs::{AutoCompletePlayer, Region},
structs::{AutocompletePlayer, Region},
utils::{wws_api::WowsApi, IsacError, IsacInfo, LoadSaveFromJson},
Context, Data, Error,
};
Expand All @@ -20,7 +20,7 @@ pub async fn link(
ctx: Context<'_>,
#[autocomplete = "autocomplete::player"]
#[description = "your game server & ign"]
player: AutoCompletePlayer, // the String is a Serialized PartialPlayer struct
player: AutocompletePlayer, // the String is a Serialized PartialPlayer struct
) -> Result<(), Error> {
let api = WowsApi::new(&ctx);
let partial_player = { player.fetch_partial_player(&api).await? };
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/wws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use poise::{
use crate::{
dc_utils::{autocomplete, Args, ContextAddon, UserAddon},
structs::{
AutoCompletePlayer, Mode, PartialPlayer, Ship, ShipClass, ShipTier, Statistic,
AutocompletePlayer, Mode, PartialPlayer, Ship, ShipClass, ShipTier, Statistic,
StatisticValueType,
},
template_data::{
Expand Down Expand Up @@ -42,7 +42,7 @@ pub async fn wws(
ship_name: Option<String>,
#[description = "player's ign, default: yourself"]
#[autocomplete = "autocomplete::player"]
player: Option<AutoCompletePlayer>,
player: Option<AutocompletePlayer>,
#[description = "@ping / discord user's ID, default: yourself"]
#[rename = "user"]
discord_user: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions src/dc_utils/autocomplete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ pub async fn clan(ctx: Context<'_>, input: &str) -> Vec<AutocompleteChoice> {

/// a temp struct for passing autocomplete result back due to the value size limit (100), can be removed if there's a better way lik command data()
#[derive(Serialize, Deserialize, Debug, Hash, PartialEq, Eq)]
pub struct AutoCompleteClan {
pub struct AutocompleteClan {
pub tag: ClanTag,
pub region: Region,
}

impl From<PartialClan> for AutoCompleteClan {
impl From<PartialClan> for AutocompleteClan {
fn from(v: PartialClan) -> Self {
Self {
tag: v.tag,
Expand Down
10 changes: 5 additions & 5 deletions src/structs/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ impl Default for BannerData {

// a intermediate struct for receiving formatted String from `autocomplete::player()`
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct AutoCompletePlayer {
pub struct AutocompletePlayer {
pub region: Region,
pub ign: String,
}

impl FromStr for AutoCompletePlayer {
impl FromStr for AutocompletePlayer {
type Err = IsacError;

/// parsing region and ign from str, for example: `[ASIA] B2U` or `ASIA B2U`
Expand All @@ -237,19 +237,19 @@ impl FromStr for AutoCompletePlayer {
}
}

impl Into<String> for AutoCompletePlayer {
impl Into<String> for AutocompletePlayer {
fn into(self) -> String {
format!("{} ({})", self.ign, self.region)
}
}

impl Into<Value> for AutoCompletePlayer {
impl Into<Value> for AutocompletePlayer {
fn into(self) -> Value {
Value::String(self.into())
}
}

impl AutoCompletePlayer {
impl AutocompletePlayer {
/// fetch the PartialPlayer
pub async fn fetch_partial_player(
&self,
Expand Down
4 changes: 2 additions & 2 deletions src/structs/user_search_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poise::serenity_prelude::UserId;
use serde::{Deserialize, Serialize};
use tokio::io::AsyncWriteExt;

use crate::structs::{lru_vector::LruVector, AutoCompletePlayer};
use crate::structs::{lru_vector::LruVector, AutocompletePlayer};

/// users searching history in autocomplete::player()
/// user's data is saved when getting evicted or bot shutting down
Expand Down Expand Up @@ -91,7 +91,7 @@ impl SearchCache {
#[derive(Debug, Serialize, Deserialize)]
pub struct UserSearchCache {
pub user_id: UserId,
pub autocomplete_player: LruVector<AutoCompletePlayer>,
pub autocomplete_player: LruVector<AutocompletePlayer>,
}

impl UserSearchCache {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/cache_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use once_cell::sync::Lazy;
use parking_lot::Mutex;

use crate::{
dc_utils::autocomplete::AutoCompleteClan,
dc_utils::autocomplete::AutocompleteClan,
structs::{
user_search_history::UserSearchCache, AutoCompletePlayer, PartialClan, PartialPlayer,
user_search_history::UserSearchCache, AutocompletePlayer, PartialClan, PartialPlayer,
Region,
},
utils::{wws_api::WowsApi, IsacError, IsacInfo},
Expand Down Expand Up @@ -56,9 +56,9 @@ pub async fn player(
/// [`IsacInfo::ClanNotFound`]
pub async fn clan(
api: &WowsApi<'_>,
autocomplete_clan: AutoCompleteClan,
autocomplete_clan: AutocompleteClan,
) -> Result<PartialClan, IsacError> {
static CACHE: Lazy<Mutex<LruCache<AutoCompleteClan, PartialClan>>> =
static CACHE: Lazy<Mutex<LruCache<AutocompleteClan, PartialClan>>> =
Lazy::new(|| Mutex::new(LruCache::new(NonZeroUsize::new(30).unwrap())));

let cache_result = {
Expand Down Expand Up @@ -90,5 +90,5 @@ pub async fn save_user_search_history(ctx: &Context<'_>, region: Region, ign: St
mg.get_or_insert_mut(&ctx.author().id, || UserSearchCache::new(ctx.author().id))
.await
.autocomplete_player
.put(AutoCompletePlayer { region, ign });
.put(AutocompletePlayer { region, ign });
}
4 changes: 2 additions & 2 deletions src/utils/isac_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum IsacInfo {
NeedPremium {
msg: String,
},
AutoCompleteError,
AutocompleteError,

EmbedPermission,
}
Expand Down Expand Up @@ -127,7 +127,7 @@ impl Display for IsacInfo {
mode.upper()
)
}
IsacInfo::AutoCompleteError => {
IsacInfo::AutocompleteError => {
"❌ please select an option in the results!".to_string()
}
IsacInfo::ClanNoBattle { clan, season } => format!(
Expand Down
6 changes: 3 additions & 3 deletions src/utils/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use once_cell::sync::Lazy;
use regex::Regex;

use crate::{
dc_utils::autocomplete::AutoCompleteClan,
dc_utils::autocomplete::AutocompleteClan,
structs::{ClanTag, Region},
utils::{IsacError, IsacInfo},
};

// parsing region and clan tag from str, for example: `[PANTS] Dont Cap Kill All (ASIA)`
/// # Error
/// [`IsacInfo::GeneralError`] if received a malformed input
pub fn parse_region_clan(input: &str) -> Result<AutoCompleteClan, IsacError> {
pub fn parse_region_clan(input: &str) -> Result<AutocompleteClan, IsacError> {
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[([\w|-]+)].+\((\w+)\)").unwrap());
let (_, [clan_tag, region_str]) = RE
.captures(input)
Expand All @@ -21,7 +21,7 @@ pub fn parse_region_clan(input: &str) -> Result<AutoCompleteClan, IsacError> {
let region = Region::parse(region_str).ok_or(IsacInfo::GeneralError {
msg: format!("`{region_str}` is not a valid region"),
})?;
Ok(AutoCompleteClan {
Ok(AutocompleteClan {
tag: ClanTag::from(clan_tag),
region,
})
Expand Down
6 changes: 3 additions & 3 deletions src/utils/wws_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use strum::IntoEnumIterator;

use crate::{
structs::{
api, AutoCompletePlayer, Clan, ClanDetail, ClanDetailAPIRes, ClanInfoAPIRes,
api, AutocompletePlayer, Clan, ClanDetail, ClanDetailAPIRes, ClanInfoAPIRes,
ClanMemberAPIRes, ClanTag, Mode, PartialClan, PartialPlayer, Player, PlayerClanAPIRes,
PlayerClanBattle, PlayerClanBattleAPIRes, Region, ShipId, ShipStatsCollection, ShipsPara,
VortexPlayer, VortexPlayerAPIRes, VortexShipAPIRes, VortexVehicleAPIRes,
Expand Down Expand Up @@ -400,8 +400,8 @@ impl Display for VortexPlayerSearch {

impl VortexPlayerSearch {
/// for turning it into [`AutocompleteChoice`]
pub fn to_autocomplete_player(self, region: Region) -> AutoCompletePlayer {
AutoCompletePlayer {
pub fn to_autocomplete_player(self, region: Region) -> AutocompletePlayer {
AutocompletePlayer {
region,
ign: self.name,
}
Expand Down

0 comments on commit 71cdfd8

Please sign in to comment.