From 9ecece1a5b78fa3475ea477fec5cddc545838464 Mon Sep 17 00:00:00 2001 From: Max batleforc Date: Tue, 27 May 2025 19:49:29 +0200 Subject: [PATCH] feat: Split des packages --- Cargo.lock | 37 ++++++++++++++-- Cargo.toml | 24 ++++++----- Readme.md | 1 - apps/{bot => cli}/Cargo.toml | 4 +- apps/{bot => cli}/project.json | 12 +++--- apps/{bot => cli}/src/banner.art | 0 apps/{bot => cli}/src/main.rs | 4 -- libs/bot/Cargo.toml | 17 ++++++++ libs/bot/project.json | 43 +++++++++++++++++++ .../bot/src/bot => libs/bot/src}/event/mod.rs | 2 +- .../src/bot => libs/bot/src}/helper/mod.rs | 2 +- .../bot/src/bot/mod.rs => libs/bot/src/lib.rs | 2 +- .../src/bot => libs/bot/src}/trivia/config.rs | 4 +- .../src/bot => libs/bot/src}/trivia/create.rs | 4 +- .../src/bot => libs/bot/src}/trivia/list.rs | 4 +- .../src/bot => libs/bot/src}/trivia/mod.rs | 2 +- .../src/bot => libs/bot/src}/utility/age.rs | 2 +- .../src/bot => libs/bot/src}/utility/help.rs | 2 +- .../src/bot => libs/bot/src}/utility/mod.rs | 0 .../bot => libs/bot/src}/utility/server.rs | 2 +- libs/config/Cargo.toml | 13 ++++++ libs/config/project.json | 43 +++++++++++++++++++ {apps/bot => libs/config}/src/dotenv/mod.rs | 0 .../src/config.rs => libs/config/src/lib.rs | 2 +- 24 files changed, 185 insertions(+), 41 deletions(-) rename apps/{bot => cli}/Cargo.toml (87%) rename apps/{bot => cli}/project.json (83%) rename apps/{bot => cli}/src/banner.art (100%) rename apps/{bot => cli}/src/main.rs (94%) create mode 100644 libs/bot/Cargo.toml create mode 100644 libs/bot/project.json rename {apps/bot/src/bot => libs/bot/src}/event/mod.rs (96%) rename {apps/bot/src/bot => libs/bot/src}/helper/mod.rs (98%) rename apps/bot/src/bot/mod.rs => libs/bot/src/lib.rs (98%) rename {apps/bot/src/bot => libs/bot/src}/trivia/config.rs (98%) rename {apps/bot/src/bot => libs/bot/src}/trivia/create.rs (97%) rename {apps/bot/src/bot => libs/bot/src}/trivia/list.rs (98%) rename {apps/bot/src/bot => libs/bot/src}/trivia/mod.rs (93%) rename {apps/bot/src/bot => libs/bot/src}/utility/age.rs (95%) rename {apps/bot/src/bot => libs/bot/src}/utility/help.rs (97%) rename {apps/bot/src/bot => libs/bot/src}/utility/mod.rs (100%) rename {apps/bot/src/bot => libs/bot/src}/utility/server.rs (91%) create mode 100644 libs/config/Cargo.toml create mode 100644 libs/config/project.json rename {apps/bot => libs/config}/src/dotenv/mod.rs (100%) rename apps/bot/src/config.rs => libs/config/src/lib.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 0dc955d..98ab6d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,15 +404,12 @@ dependencies = [ "chrono", "clickhouse", "clickhouse_pool", + "config", "database", "poise", "serde", "tokio", - "tokio-cron-scheduler", - "toml", - "tool_tracing", "tracing", - "uuid", ] [[package]] @@ -524,6 +521,26 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93a719913643003b84bd13022b4b7e703c09342cd03b679c4641c7d2e50dc34d" +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "bot", + "chrono", + "clickhouse", + "clickhouse_pool", + "config", + "database", + "poise", + "serde", + "tokio", + "tokio-cron-scheduler", + "toml", + "tool_tracing", + "tracing", + "uuid", +] + [[package]] name = "clickhouse" version = "0.13.2" @@ -583,6 +600,18 @@ dependencies = [ "url", ] +[[package]] +name = "config" +version = "0.1.0" +dependencies = [ + "database", + "poise", + "serde", + "toml", + "tool_tracing", + "tracing", +] + [[package]] name = "core-foundation" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 6fcd77a..425f66c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,28 +2,30 @@ [workspace] resolver = '2' members = [ - 'apps/bot', - 'libs/tool_tracing', - 'libs/clickhouse_pool', - 'libs/database', + 'apps/cli', + 'libs/tool_tracing', + 'libs/clickhouse_pool', + 'libs/database', + 'libs/bot', + 'libs/config', ] [workspace.dependencies] -poise = { git = "https://github.com/serenity-rs/poise", branch = "current" } +poise = { git = 'https://github.com/serenity-rs/poise', branch = 'current' } tokio = { version = '1.45.0', features = [ - 'macros', - 'rt-multi-thread', - 'io-std', + 'macros', + 'rt-multi-thread', + 'io-std', ] } serde = '1.0' tracing = '0.1' serde_json = '1.0' clickhouse = { version = '0.13', features = ['native-tls', 'uuid', 'chrono'] } -uuid = { version = "1.16", features = ["serde", "v4"] } -chrono = { version = "0.4.41", features = ["serde"] } +uuid = { version = '1.16', features = ['serde', 'v4'] } +chrono = { version = '0.4.41', features = ['serde'] } [profile.release] lto = true [patch.crates-io] -serenity = { git = "https://github.com/serenity-rs/serenity", branch = "current" } +serenity = { git = 'https://github.com/serenity-rs/serenity', branch = 'current' } diff --git a/Readme.md b/Readme.md index bc9ac08..a678f5f 100644 --- a/Readme.md +++ b/Readme.md @@ -24,7 +24,6 @@ - [ ] [ADMIN] trivial add-question : Ajout de question + réponse ou X réponse - [ ] [ADMIN] trivial del-question : Suppression de question - [ ] [ADMIN] trivial load-question : Charge un fichier/lien de question -- [ ] [ADMIN] trivial choose-chan : Choix du channel - [ ] trivial scoreboard : Scoreboard - [ ] trivial score : Score d'une personne par défaut le sien - [ ] trivial top : Top X par défaut 3 diff --git a/apps/bot/Cargo.toml b/apps/cli/Cargo.toml similarity index 87% rename from apps/bot/Cargo.toml rename to apps/cli/Cargo.toml index 5f5ae23..4986deb 100644 --- a/apps/bot/Cargo.toml +++ b/apps/cli/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "bot" +name = "cli" version = "0.1.0" edition = "2021" @@ -20,5 +20,7 @@ tokio-cron-scheduler = { version = "0.14", features = [ "tracing-subscriber", "signal", ] } +config = { path = "../../libs/config" } +bot = { path = "../../libs/bot" } # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/apps/bot/project.json b/apps/cli/project.json similarity index 83% rename from apps/bot/project.json rename to apps/cli/project.json index c74d335..6863f76 100644 --- a/apps/bot/project.json +++ b/apps/cli/project.json @@ -1,8 +1,8 @@ { - "name": "bot", + "name": "cli", "$schema": "../../node_modules/nx/schemas/project-schema.json", "projectType": "application", - "sourceRoot": "apps/bot/src", + "sourceRoot": "apps/cli/src", "targets": { "build": { "cache": true, @@ -11,7 +11,7 @@ "{options.target-dir}" ], "options": { - "target-dir": "dist/target/bot" + "target-dir": "dist/target/cli" }, "configurations": { "production": { @@ -26,7 +26,7 @@ "{options.target-dir}" ], "options": { - "target-dir": "dist/target/bot" + "target-dir": "dist/target/cli" }, "configurations": { "production": { @@ -41,7 +41,7 @@ "{options.target-dir}" ], "options": { - "target-dir": "dist/target/bot" + "target-dir": "dist/target/cli" } }, "run": { @@ -50,7 +50,7 @@ "{options.target-dir}" ], "options": { - "target-dir": "dist/target/bot" + "target-dir": "dist/target/cli" }, "configurations": { "production": { diff --git a/apps/bot/src/banner.art b/apps/cli/src/banner.art similarity index 100% rename from apps/bot/src/banner.art rename to apps/cli/src/banner.art diff --git a/apps/bot/src/main.rs b/apps/cli/src/main.rs similarity index 94% rename from apps/bot/src/main.rs rename to apps/cli/src/main.rs index 5119a4d..93c9313 100644 --- a/apps/bot/src/main.rs +++ b/apps/cli/src/main.rs @@ -2,10 +2,6 @@ use bot::start_bot; use config::parse_local_config; use tracing::{error, info}; -pub mod bot; -pub mod config; -pub mod dotenv; - #[tokio::main] async fn main() { println!(include_str!("banner.art")); diff --git a/libs/bot/Cargo.toml b/libs/bot/Cargo.toml new file mode 100644 index 0000000..9951c55 --- /dev/null +++ b/libs/bot/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "bot" +version = "0.1.0" +edition = "2021" + +[dependencies] +poise = { workspace = true } +tokio = { workspace = true } +serde = { workspace = true } +tracing = { workspace = true } +clickhouse_pool = { path = "../../libs/clickhouse_pool" } +clickhouse = { workspace = true } +chrono = { workspace = true } +config = { path = "../../libs/config" } +database = { path = "../../libs/database" } + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libs/bot/project.json b/libs/bot/project.json new file mode 100644 index 0000000..48c83c4 --- /dev/null +++ b/libs/bot/project.json @@ -0,0 +1,43 @@ +{ + "name": "bot", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "projectType": "library", + "sourceRoot": "libs/bot/src", + "targets": { + "build": { + "executor": "@monodon/rust:check", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/bot" + } + }, + "test": { + "cache": true, + "executor": "@monodon/rust:test", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/bot" + }, + "configurations": { + "production": { + "release": true + } + } + }, + "lint": { + "cache": true, + "executor": "@monodon/rust:lint", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/bot" + } + } + }, + "tags": [] +} diff --git a/apps/bot/src/bot/event/mod.rs b/libs/bot/src/event/mod.rs similarity index 96% rename from apps/bot/src/bot/event/mod.rs rename to libs/bot/src/event/mod.rs index 74cf5f5..c8b6d95 100644 --- a/apps/bot/src/bot/event/mod.rs +++ b/libs/bot/src/event/mod.rs @@ -1,4 +1,4 @@ -use crate::bot::{Data, Error}; +use crate::{Data, Error}; use poise::serenity_prelude::{self as serenity, ActivityData}; use tracing::info; diff --git a/apps/bot/src/bot/helper/mod.rs b/libs/bot/src/helper/mod.rs similarity index 98% rename from apps/bot/src/bot/helper/mod.rs rename to libs/bot/src/helper/mod.rs index cf29220..5a87559 100644 --- a/apps/bot/src/bot/helper/mod.rs +++ b/libs/bot/src/helper/mod.rs @@ -2,7 +2,7 @@ use clickhouse_pool::traits::Model; use database::guild::Guild; use tracing::{info, warn}; -use crate::bot::{Context, Error}; +use crate::{Context, Error}; /// Check if the guild has been initialized, if it is check if user is in list of admins /// If not, check the user's permissions diff --git a/apps/bot/src/bot/mod.rs b/libs/bot/src/lib.rs similarity index 98% rename from apps/bot/src/bot/mod.rs rename to libs/bot/src/lib.rs index 0a5e5f7..9584e23 100644 --- a/apps/bot/src/bot/mod.rs +++ b/libs/bot/src/lib.rs @@ -7,7 +7,7 @@ use tracing::info; use trivia::trivia; use utility::{age::age, help::help, server::servers}; -use crate::config::Config; +use config::Config; pub mod event; pub mod helper; diff --git a/apps/bot/src/bot/trivia/config.rs b/libs/bot/src/trivia/config.rs similarity index 98% rename from apps/bot/src/bot/trivia/config.rs rename to libs/bot/src/trivia/config.rs index 0d96705..dabaff3 100644 --- a/apps/bot/src/bot/trivia/config.rs +++ b/libs/bot/src/trivia/config.rs @@ -1,5 +1,5 @@ -use crate::bot::helper::is_user_admin_right; -use crate::bot::{Context, Error}; +use crate::helper::is_user_admin_right; +use crate::{Context, Error}; use clickhouse_pool::traits::Model; use database::trivial::{Trivial, TrivialRewardKind}; use poise::serenity_prelude::{Channel, Role}; diff --git a/apps/bot/src/bot/trivia/create.rs b/libs/bot/src/trivia/create.rs similarity index 97% rename from apps/bot/src/bot/trivia/create.rs rename to libs/bot/src/trivia/create.rs index a98d983..0176dfa 100644 --- a/apps/bot/src/bot/trivia/create.rs +++ b/libs/bot/src/trivia/create.rs @@ -1,5 +1,5 @@ -use crate::bot::helper::is_user_admin_right; -use crate::bot::{Context, Error}; +use crate::helper::is_user_admin_right; +use crate::{Context, Error}; use clickhouse_pool::traits::Model; use database::trivial::Trivial; use poise::serenity_prelude; diff --git a/apps/bot/src/bot/trivia/list.rs b/libs/bot/src/trivia/list.rs similarity index 98% rename from apps/bot/src/bot/trivia/list.rs rename to libs/bot/src/trivia/list.rs index c6d730f..825ccbb 100644 --- a/apps/bot/src/bot/trivia/list.rs +++ b/libs/bot/src/trivia/list.rs @@ -1,5 +1,5 @@ -use crate::bot::helper::is_user_admin_right; -use crate::bot::{Context, Error}; +use crate::helper::is_user_admin_right; +use crate::{Context, Error}; use clickhouse_pool::traits::Model; use database::trivial::Trivial; use poise::{ diff --git a/apps/bot/src/bot/trivia/mod.rs b/libs/bot/src/trivia/mod.rs similarity index 93% rename from apps/bot/src/bot/trivia/mod.rs rename to libs/bot/src/trivia/mod.rs index 4a4e997..3b50348 100644 --- a/apps/bot/src/bot/trivia/mod.rs +++ b/libs/bot/src/trivia/mod.rs @@ -2,7 +2,7 @@ pub mod config; pub mod create; pub mod list; -use crate::bot::{Context, Error}; +use crate::{Context, Error}; use config::config; use create::create; use list::list; diff --git a/apps/bot/src/bot/utility/age.rs b/libs/bot/src/utility/age.rs similarity index 95% rename from apps/bot/src/bot/utility/age.rs rename to libs/bot/src/utility/age.rs index e268418..bd15141 100644 --- a/apps/bot/src/bot/utility/age.rs +++ b/libs/bot/src/utility/age.rs @@ -1,4 +1,4 @@ -use crate::bot::{Context, Error}; +use crate::{Context, Error}; use poise::serenity_prelude as serenity; use tracing::instrument; diff --git a/apps/bot/src/bot/utility/help.rs b/libs/bot/src/utility/help.rs similarity index 97% rename from apps/bot/src/bot/utility/help.rs rename to libs/bot/src/utility/help.rs index 5739bf9..d1888ad 100644 --- a/apps/bot/src/bot/utility/help.rs +++ b/libs/bot/src/utility/help.rs @@ -1,4 +1,4 @@ -use crate::bot::{Context, Error}; +use crate::{Context, Error}; use poise::builtins::PrettyHelpConfiguration; use tracing::instrument; diff --git a/apps/bot/src/bot/utility/mod.rs b/libs/bot/src/utility/mod.rs similarity index 100% rename from apps/bot/src/bot/utility/mod.rs rename to libs/bot/src/utility/mod.rs diff --git a/apps/bot/src/bot/utility/server.rs b/libs/bot/src/utility/server.rs similarity index 91% rename from apps/bot/src/bot/utility/server.rs rename to libs/bot/src/utility/server.rs index 45cfbaa..db1d12a 100644 --- a/apps/bot/src/bot/utility/server.rs +++ b/libs/bot/src/utility/server.rs @@ -1,4 +1,4 @@ -use crate::bot::{Context, Error}; +use crate::{Context, Error}; use tracing::instrument; /// Lists all servers the bot is in diff --git a/libs/config/Cargo.toml b/libs/config/Cargo.toml new file mode 100644 index 0000000..f990ea6 --- /dev/null +++ b/libs/config/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "config" +version = "0.1.0" +edition = "2021" + +[dependencies] +poise = { workspace = true } +serde = { workspace = true } +database = { path = "../../libs/database" } +tool_tracing = { path = "../../libs/tool_tracing" } +toml = "0.8" +tracing = { workspace = true } +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libs/config/project.json b/libs/config/project.json new file mode 100644 index 0000000..4179e95 --- /dev/null +++ b/libs/config/project.json @@ -0,0 +1,43 @@ +{ + "name": "config", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "projectType": "library", + "sourceRoot": "libs/config/src", + "targets": { + "build": { + "executor": "@monodon/rust:check", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/config" + } + }, + "test": { + "cache": true, + "executor": "@monodon/rust:test", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/config" + }, + "configurations": { + "production": { + "release": true + } + } + }, + "lint": { + "cache": true, + "executor": "@monodon/rust:lint", + "outputs": [ + "{options.target-dir}" + ], + "options": { + "target-dir": "dist/target/config" + } + } + }, + "tags": [] +} diff --git a/apps/bot/src/dotenv/mod.rs b/libs/config/src/dotenv/mod.rs similarity index 100% rename from apps/bot/src/dotenv/mod.rs rename to libs/config/src/dotenv/mod.rs diff --git a/apps/bot/src/config.rs b/libs/config/src/lib.rs similarity index 99% rename from apps/bot/src/config.rs rename to libs/config/src/lib.rs index 2dcb19e..626d833 100644 --- a/apps/bot/src/config.rs +++ b/libs/config/src/lib.rs @@ -4,7 +4,7 @@ use serde::Deserialize; use std::{env, fs::read_to_string, path::PathBuf}; use tool_tracing::tracing_kind::Tracing; -use crate::dotenv; +pub mod dotenv; const BOT_NAME: &str = "BOT_NAME"; const BOT_TOKEN: &str = "BOT_TOKEN";