From 06005b6af47e8972b495deec495c915aa5e8afd8 Mon Sep 17 00:00:00 2001 From: Xyon Date: Tue, 26 Sep 2023 01:43:49 +0100 Subject: [PATCH] Support switch to psql and token deployment --- .gitea/workflows/deploy.yaml | 7 +++ .idea/dataSources.xml | 10 ++++ .idea/sqldialects.xml | 2 +- Cargo.lock | 51 ++++++++++--------- Cargo.toml | 4 +- config/development.badgey.json | 7 +++ config/production.badgey.json | 7 +++ .../up.sql | 40 +++++++-------- src/badgey/events.rs | 5 ++ 9 files changed, 85 insertions(+), 48 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 88ed0c3..84f86ce 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -8,6 +8,8 @@ on: jobs: build: runs-on: rust + container: + options: --dns 172.16.255.254 steps: - name: Checkout uses: actions/checkout@v3 @@ -15,5 +17,10 @@ jobs: run: mkdir -pv ~/.ssh && ssh-keyscan -t rsa badgey >> ~/.ssh/known_hosts - name: Build (Release) run: cargo build --release --color=always + - uses: actions/replace-tokens@v1 + with: + files: config/production.badgey.json + env: + POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} - name: Deploy run: bash cicd/deploy.sh diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 9396fa4..ace78ba 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -8,5 +8,15 @@ jdbc:sqlite:$PROJECT_DIR$/manifold.db $ProjectFileDir$ + + postgresql + true + org.postgresql.Driver + jdbc:postgresql://localhost:5432/badgey_development + + + + $ProjectFileDir$ + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index 7add919..5a52f7b 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 14fcf52..dbaf5b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,7 +159,7 @@ dependencies = [ [[package]] name = "badgey" -version = "2.0.0" +version = "3.0.0" dependencies = [ "built", "clap", @@ -303,18 +303,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.4" +version = "4.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1d7b8d5ec32af0fadc644bf1fd509a688c2103b185644bb1e29d164e0703136" +checksum = "824956d0dca8334758a5b7f7e50518d66ea319330cbceedcf76905c2f6ab30e3" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.4.4" +version = "4.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5179bb514e4d7c2051749d8fcefa2ed6d06a9f4e6d69faf3805f5d80b8cf8d56" +checksum = "122ec64120a49b4563ccaedcbea7818d069ed8e9aa6d829b82d8a4128936b2ab" dependencies = [ "anstream", "anstyle", @@ -478,22 +478,24 @@ dependencies = [ [[package]] name = "diesel" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d98235fdc2f355d330a8244184ab6b4b33c28679c0b4158f63138e51d6cf7e88" +checksum = "53c8a2cb22327206568569e5a45bb5a2c946455efdd76e24d15b7e82171af95e" dependencies = [ + "bitflags 2.4.0", + "byteorder", "chrono", "diesel_derives", - "libsqlite3-sys", + "itoa", + "pq-sys", "r2d2", - "time", ] [[package]] name = "diesel_derives" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e054665eaf6d97d1e7125512bb2d35d07c73ac86cc6920174cb42d1ab697a554" +checksum = "ef8337737574f55a468005a83499da720f20c65586241ffea339db9ecdfd2b44" dependencies = [ "diesel_table_macro_syntax", "proc-macro2", @@ -609,9 +611,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "flate2" @@ -1042,16 +1044,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libsqlite3-sys" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" -dependencies = [ - "pkg-config", - "vcpkg", -] - [[package]] name = "libz-sys" version = "1.1.12" @@ -1094,8 +1086,8 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "manifold" -version = "4.0.0" -source = "git+https://code.orbiter-radio.uk/discord/manifold.git#3d712fdcb32f4a6269d12b25b10371e1c307e272" +version = "5.0.0" +source = "git+https://code.orbiter-radio.uk/discord/manifold.git#742609b4afdc4ba328cfb9df68c9e705a96b2704" dependencies = [ "built", "chrono", @@ -1568,6 +1560,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "pq-sys" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31c0052426df997c0cbd30789eb44ca097e3541717a7b8fa36b1c464ee7edebd" +dependencies = [ + "vcpkg", +] + [[package]] name = "proc-macro2" version = "1.0.67" diff --git a/Cargo.toml b/Cargo.toml index d13da2b..75e70c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "badgey" -version = "2.0.0" +version = "3.0.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,7 +11,7 @@ built = { version = "0.6.0", features = ["git2", "semver", "chrono"] } [dependencies] built = { version = "0.6.0", features = ["git2", "semver", "chrono"] } clap = { version = "4.3.23", features = ["cargo"] } -diesel = { version = "2.1.0", features = ["sqlite", "r2d2", "chrono"] } +diesel = { version = "2.1.0", features = ["postgres", "r2d2", "chrono"] } diesel_migrations = "2.1.0" env_logger = "0.10.0" log = "0.4.20" diff --git a/config/development.badgey.json b/config/development.badgey.json index 838bd9e..0329d84 100644 --- a/config/development.badgey.json +++ b/config/development.badgey.json @@ -1,6 +1,13 @@ { "prefix": "-", "nickname": "Badgey (Development Edition)", + "database": { + "host": "127.0.0.1", + "user": "badgey_development", + "pass": "", + "database_name": "badgey_development", + "port": 5432 + }, "channels": { "log": 648260641626390528 }, diff --git a/config/production.badgey.json b/config/production.badgey.json index 1912609..ee602c5 100644 --- a/config/production.badgey.json +++ b/config/production.badgey.json @@ -4,6 +4,13 @@ "channels": { "log": 1143479696886087801 }, + "database": { + "host": "127.0.0.1", + "user": "postgres", + "pass": "#{POSTGRES_PASSWORD}#", + "database_name": "badgey", + "port": 5432 + }, "responses_file_path": "txt/responses.txt", "services": { "weather": { diff --git a/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql b/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql index 735856e..1e96e3d 100644 --- a/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql +++ b/migrations/2023-09-20-230922_extend userinfo to include XP/up.sql @@ -25,25 +25,25 @@ CREATE TABLE IF NOT EXISTS "ranks" ); INSERT INTO "tracks" (track_id, track_name) VALUES - (0, "officer"), - (1, "enlisted"); + (0, 'officer'), + (1, 'enlisted'); INSERT INTO "ranks" (role_id, required_level, rank_track, rank_name) VALUES - (1154403063960961063, 0, 0, "cadet first year"), -- cadet 1 - (1154403107313307729, 10, 0, "cadet fourth year"), -- cadet 4 - (1152963553620393995, 20, 0, "ensign"), -- ensign - (1152963552299188224, 30, 0, "lieutenant junior grade"), -- ltjg - (1152963550906695762, 40, 0, "lieutenant"), -- lt - (1152963549979758712, 50, 0, "lieutenant commander"), -- ltcmdr - (1152963548843094126, 60, 0, "commander"), -- cmdr - (1152963541255594054, 80, 0, "captain"), -- capt - (1152759044893843656, 100, 0, "fleet captain"), -- fleetcapt - (1152965025938550926, 0, 1, "crewman third class"), -- crewman 3rd - (1152965024550228099, 10, 1, "crewman second class"), -- crewman 2nd - (1152965023098994789, 20, 1, "crewman first class"), -- crewman 1st - (1152964462844846162, 30, 1, "petty officer third class"), -- petty 3rd - (1152964461817253958, 40, 1, "petty officer second class"), -- petty 2nd - (1152964460835778631, 50, 1, "petty officer first class"), -- petty 1st - (1152963559010087022, 60, 1, "chief petty officer"), -- chief petty - (1152963557537886229, 80, 1, "senior chief petty officer"), -- sr ch petty - (1152963556527063110, 100, 1, "master chief petty officer"); -- master ch petty + (1154403063960961063, 0, 0, 'cadet first year'), -- cadet 1 + (1154403107313307729, 5, 0, 'cadet fourth year'), -- cadet 4 + (1152963553620393995, 10, 0, 'ensign'), -- ensign + (1152963552299188224, 20, 0, 'lieutenant junior grade'), -- ltjg + (1152963550906695762, 30, 0, 'lieutenant'), -- lt + (1152963549979758712, 40, 0, 'lieutenant commander'), -- ltcmdr + (1152963548843094126, 50, 0, 'commander'), -- cmdr + (1152963541255594054, 75, 0, 'captain'), -- capt + (1152759044893843656, 100, 0, 'fleet captain'), -- fleetcapt + (1152965025938550926, 0, 1, 'crewman third class'), -- crewman 3rd + (1152965024550228099, 5, 1, 'crewman second class'), -- crewman 2nd + (1152965023098994789, 10, 1, 'crewman first class'), -- crewman 1st + (1152964462844846162, 20, 1, 'petty officer third class'), -- petty 3rd + (1152964461817253958, 30, 1, 'petty officer second class'), -- petty 2nd + (1152964460835778631, 40, 1, 'petty officer first class'), -- petty 1st + (1152963559010087022, 50, 1, 'chief petty officer'), -- chief petty + (1152963557537886229, 75, 1, 'senior chief petty officer'), -- sr ch petty + (1152963556527063110, 100, 1, 'master chief petty officer'); -- master ch petty diff --git a/src/badgey/events.rs b/src/badgey/events.rs index 8eb7568..04671b9 100644 --- a/src/badgey/events.rs +++ b/src/badgey/events.rs @@ -32,6 +32,11 @@ impl BadgeyHandler { return Ok(()) } + if fctx.user_data().await.user_info.lock().await.get_mut(&msg.author.id.as_u64()).is_none() { + debug!("Tried to add XP to a user we don't know about, aborting."); + return Ok(()) + } + let db = &fctx.user_data().await.database; let mut rng = SmallRng::from_entropy(); let xp_reward = rng.gen_range(1..30).clone();