Skip to content

Commit

Permalink
🧹🧹🧹🧹🧹🧹
Browse files Browse the repository at this point in the history
  • Loading branch information
pawarherschel committed Mar 23, 2024
1 parent 8a29ded commit 462ed61
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 304 deletions.
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
pub mod zaphkiel {
pub mod cpu_info;
pub mod db;
pub mod gamelog_join_leave;
pub mod group_access_type;
pub mod join_leave_event;
pub mod macros;
// pub mod utils;
// pub mod cache;
pub mod cpu_info;
pub mod vertex;
pub mod world_instance;
pub mod world_regions;
Expand Down
209 changes: 0 additions & 209 deletions src/zaphkiel/cache.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/zaphkiel/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use sqlx::{Sqlite, SqlitePool};

use crate::zaphkiel::cpu_info::CPU_THREADS;

#[allow(clippy::missing_panics_doc)]
pub async fn establish_connection() -> SqlitePool {
sqlx::pool::PoolOptions::<Sqlite>::new()
.acquire_timeout(Duration::from_secs(60 * 60))
Expand Down
16 changes: 10 additions & 6 deletions src/zaphkiel/gamelog_join_leave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::zaphkiel::join_leave_event::JoinLeaveEvent;
use crate::zaphkiel::world_instance::WorldInstance;

#[derive(Debug, sqlx::FromRow, Clone)]
#[allow(clippy::module_name_repetitions)] // I want to keep the name ~kat
pub struct GamelogJoinLeaveRow {
pub id: i64,
pub created_at: String,
Expand All @@ -40,6 +41,12 @@ pub struct GamelogJoinLeave {
pub time: Option<u64>,
}

impl Default for GamelogJoinLeave {
fn default() -> Self {
Self::new()
}
}

impl GamelogJoinLeave {
#[must_use]
pub fn new() -> Self {
Expand All @@ -58,25 +65,22 @@ impl GamelogJoinLeave {
}
}

#[allow(clippy::fallible_impl_from)] // we want it to fail when it's wrong
impl From<GamelogJoinLeaveRow> for GamelogJoinLeave {
fn from(row: GamelogJoinLeaveRow) -> Self {
let mut ret = Self::new();
ret.id = row.id;
ret.created_at = row.created_at.parse().unwrap();
ret.event = row.r#type.parse().unwrap();
ret.display_name = row.display_name.into();
ret.location = if let Ok(location) = row.location.parse() {
Some(location)
} else {
None
};
ret.location = row.location.parse().ok();
ret.user_id = match row.user_id {
x if x.is_empty() => None,
_ => Some(row.user_id.into()),
};
ret.time = match row.time {
..=0 => None,
_ => Some(row.time as u64),
_ => Some(row.time.try_into().unwrap()),
};

ret
Expand Down
9 changes: 5 additions & 4 deletions src/zaphkiel/group_access_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ impl From<&str> for GroupAccessType {
}
}

#[allow(clippy::fallible_impl_from)] // we WANT it to fail if it's wrong
impl From<String> for GroupAccessType {
fn from(value: String) -> Self {
let value = value.to_lowercase();
match value.as_str() {
"public" => GroupAccessType::Public,
"plus" => GroupAccessType::Plus,
"members" => GroupAccessType::Members,
_ => panic!("Unknown group access type: {}", value),
"public" => Self::Public,
"plus" => Self::Plus,
"members" => Self::Members,
_ => panic!("Unknown group access type: {value}"),
}
}
}
15 changes: 4 additions & 11 deletions src/zaphkiel/join_leave_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,16 @@ impl From<&str> for JoinLeaveEvent {
}
}

#[allow(clippy::fallible_impl_from)] // we want it to fail if it's wrong
impl From<String> for JoinLeaveEvent {
fn from(value: String) -> Self {
let value = value.to_lowercase();
match value.as_str() {
"join" => JoinLeaveEvent::Join,
"leave" => JoinLeaveEvent::Leave,
"join" | "joins" | "joined" | "onplayerjoined" => Self::Join,

"joins" => JoinLeaveEvent::Join,
"leaves" => JoinLeaveEvent::Leave,
"leave" | "leaves" | "left" | "onplayerleft" => Self::Leave,

"joined" => JoinLeaveEvent::Join,
"left" => JoinLeaveEvent::Leave,

"onplayerjoined" => JoinLeaveEvent::Join,
"onplayerleft" => JoinLeaveEvent::Leave,

_ => panic!("Unknown join/leave event: {}", value),
_ => panic!("Unknown join/leave event: {value}"),
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions src/zaphkiel/utils.rs

This file was deleted.

6 changes: 3 additions & 3 deletions src/zaphkiel/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ impl Hash for Vertex {
}

impl Vertex {
pub fn new(name: impl ToString) -> Vertex {
Vertex {
pub fn new(name: &impl ToString) -> Self {
Self {
user_id: name.to_string(),
..Default::default()
}
}
}

impl Vertex {
pub fn add(&mut self, other: Vertex) {
pub fn add(&mut self, other: Self) {
let old = self.everyone_else.get(&other).unwrap_or(&0);
self.everyone_else.insert(other, old + 1);
}
Expand Down
Loading

0 comments on commit 462ed61

Please sign in to comment.