Create client to establish connection with discord and add basic framework with sample command

This commit is contained in:
2025-01-29 22:22:08 +00:00
parent fc07051558
commit a719b143de
50 changed files with 1712 additions and 128 deletions

7
cipher_core/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "cipher_core"
version = "0.1.0"
edition = "2021"
[dependencies]
async-trait = "0.1.85"

1
cipher_core/src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod repository;

View File

@@ -0,0 +1,35 @@
use std::fmt::Display;
use user_repository::UserRepository;
pub mod user_repository;
#[async_trait::async_trait]
pub trait RepositoryProvider {
type BackendError: std::error::Error;
type Repository<'a>: Repository<BackendError = <Self as RepositoryProvider>::BackendError> + Send + Sync
where
Self: 'a;
async fn get(&self) -> Result<Self::Repository<'_>, RepositoryError<Self::BackendError>>;
}
pub trait Repository
where
Self: UserRepository<BackendError = <Self as Repository>::BackendError>,
{
type BackendError: std::error::Error;
}
#[derive(Debug)]
pub struct RepositoryError<E>(pub E);
impl<E> Display for RepositoryError<E>
where
E: Display,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}

View File

@@ -0,0 +1,29 @@
use super::RepositoryError;
#[async_trait::async_trait]
pub trait UserRepository {
type BackendError: std::error::Error;
async fn user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
async fn insert_user(&mut self, new_user: NewUser) -> Result<User, RepositoryError<Self::BackendError>>;
async fn update_user(&mut self, user: User) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
async fn remove_user(&mut self, id: i32) -> Result<Option<User>, RepositoryError<Self::BackendError>>;
}
pub struct User {
pub id: i32,
pub discord_user_id: u64,
pub pokemon_go_code: Option<String>,
pub pokemon_pocket_code: Option<String>,
pub switch_code: Option<String>,
}
pub struct NewUser {
pub discord_user_id: u64,
pub pokemon_go_code: Option<String>,
pub pokemon_pocket_code: Option<String>,
pub switch_code: Option<String>,
}