Housekeeping
Some checks failed
Build and push Docker image / build (push) Failing after 1m1s
Build and push Docker image / deploy (push) Has been skipped

This commit is contained in:
toast 2024-09-22 02:49:01 +10:00
parent cf8caf1aae
commit 306e55d866
16 changed files with 330 additions and 458 deletions

View File

@ -1,7 +1,9 @@
.vscode .vscode
target .cargo
.env .env
.gitignore .gitignore
.gitattributes
docker-compose.yml docker-compose.yml
Dockerfile
renovate.json renovate.json
run.sh run.sh

View File

@ -1,13 +1,18 @@
name: Build and push container image name: Build and push Docker image
on: on:
push: push:
branches: branches:
- master - master
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
build: build:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- name: Set up Docker environment - name: Set up Docker environment
run: | run: |
@ -18,36 +23,65 @@ jobs:
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update && apt install -y docker-ce docker-ce-cli containerd.io apt update && apt install -y docker-ce docker-ce-cli containerd.io
- name: Checkout branch - name: Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
- name: Checkout
uses: https://github.com/actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 uses: https://github.com/actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Cache
uses: https://github.com/actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: cache
with:
path: |
$HOME/.cargo/bin/
$HOME/.cargo/git/
$HOME/.cargo/registry/index/
$HOME/.cargo/registry/cache/
target/
key: ${{ runner.os }}-cache-${{ hashFiles('./Cargo.lock') }}
- name: Login to Gitea - name: Login to Gitea
uses: https://github.com/docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 uses: https://github.com/docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
with: with:
registry: git.toast-server.net registry: git.toast-server.net
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }} password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up Docker Buildx - name: Set up Rust toolchain
uses: https://github.com/docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3 uses: https://github.com/actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc # v1.9.0
with:
toolchain: stable
rustflags: -C target-feature=-crt-static
- name: Install zigbuild
run: |
pip3 install ziglang
cargo install --locked cargo-zigbuild
- name: Compile
run: |
rustup target add x86_64-unknown-linux-musl
export GIT_COMMIT_HASH=${{ github.sha }} && \
export GIT_COMMIT_BRANCH=${{ github.ref_name }} && \
cargo zigbuild --target x86_64-unknown-linux-musl --locked -rF production
- name: Build and push image - name: Build and push image
uses: https://github.com/docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445 # v6.5.0 uses: https://github.com/docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with: with:
context: . context: .
platforms: linux/amd64 platforms: linux/amd64
push: true push: true
tags: git.toast-server.net/toast/kon:main tags: git.toast-server.net/toast/kon:master
build-args: GIT_HASH=${{ env.GITHUB_SHA }} cache-from: type=gha
cache-from: type=registry,ref=git.toast-server.net/toast/kon:cache cache-to: type=gha,mode=max
cache-to: type=registry,ref=git.toast-server.net/toast/kon:cache,mode=max,image-manifest=true,oci-mediatypes=true
deploy: deploy:
runs-on: alpine-latest runs-on: alpine-latest
needs: build needs: build
steps: steps:
- name: Deploy update - name: Deploy update
uses: https://github.com/appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262 # v1.0.3 uses: https://github.com/appleboy/ssh-action@d732991ab09097d8c8f390d91385b0386e619598 # v1.0.3
with: with:
host: ${{ secrets.SSH_HOST }} host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }} username: ${{ secrets.SSH_USERNAME }}

253
Cargo.lock generated
View File

@ -4,18 +4,18 @@ version = 3
[[package]] [[package]]
name = "addr2line" name = "addr2line"
version = "0.22.0" version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375"
dependencies = [ dependencies = [
"gimli", "gimli",
] ]
[[package]] [[package]]
name = "adler" name = "adler2"
version = "1.0.2" version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
@ -58,13 +58,13 @@ dependencies = [
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.81" version = "0.1.82"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -81,17 +81,17 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.73" version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [ dependencies = [
"addr2line", "addr2line",
"cc",
"cfg-if", "cfg-if",
"libc", "libc",
"miniz_oxide", "miniz_oxide",
"object", "object",
"rustc-demangle", "rustc-demangle",
"windows-targets 0.52.6",
] ]
[[package]] [[package]]
@ -132,9 +132,9 @@ dependencies = [
[[package]] [[package]]
name = "bb8-redis" name = "bb8-redis"
version = "0.16.0" version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6910977c026bb1d0a6b523508d1a893d6d4c2ba216355e9569d8181d92ccbe" checksum = "1781f22daa0ae97d934fdf04a5c66646f154a164c4bdc157ec8d3c11166c05cc"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bb8", "bb8",
@ -182,9 +182,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.7.1" version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3"
[[package]] [[package]]
name = "camino" name = "camino"
@ -229,9 +229,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.1.13" version = "1.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0"
dependencies = [ dependencies = [
"shlex", "shlex",
] ]
@ -287,9 +287,9 @@ checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]] [[package]]
name = "cpufeatures" name = "cpufeatures"
version = "0.2.13" version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -368,7 +368,7 @@ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"strsim", "strsim",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -379,7 +379,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -451,14 +451,14 @@ dependencies = [
[[package]] [[package]]
name = "enum-as-inner" name = "enum-as-inner"
version = "0.6.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc"
dependencies = [ dependencies = [
"heck", "heck",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -494,9 +494,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
[[package]] [[package]]
name = "fastrand" name = "fastrand"
version = "2.1.0" version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6"
[[package]] [[package]]
name = "feed-rs" name = "feed-rs"
@ -517,9 +517,9 @@ dependencies = [
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.31" version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@ -599,7 +599,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -664,9 +664,9 @@ dependencies = [
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.29.0" version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64"
[[package]] [[package]]
name = "glob" name = "glob"
@ -720,9 +720,9 @@ checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.1" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
@ -878,15 +878,15 @@ dependencies = [
[[package]] [[package]]
name = "hyper-rustls" name = "hyper-rustls"
version = "0.27.2" version = "0.27.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333"
dependencies = [ dependencies = [
"futures-util", "futures-util",
"http 1.1.0", "http 1.1.0",
"hyper 1.4.1", "hyper 1.4.1",
"hyper-util", "hyper-util",
"rustls 0.23.12", "rustls 0.23.13",
"rustls-pki-types", "rustls-pki-types",
"tokio", "tokio",
"tokio-rustls 0.26.0", "tokio-rustls 0.26.0",
@ -911,9 +911,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper-util" name = "hyper-util"
version = "0.1.7" version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" checksum = "da62f120a8a37763efb0cf8fdf264b884c7b8b9ac8660b900c8661030c00e6ba"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -931,9 +931,9 @@ dependencies = [
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.60" version = "0.1.61"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"core-foundation-sys", "core-foundation-sys",
@ -980,9 +980,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.4.0" version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
dependencies = [ dependencies = [
"equivalent", "equivalent",
"hashbrown", "hashbrown",
@ -1002,9 +1002,9 @@ dependencies = [
[[package]] [[package]]
name = "ipnet" name = "ipnet"
version = "2.9.0" version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4"
[[package]] [[package]]
name = "itoa" name = "itoa"
@ -1023,7 +1023,7 @@ dependencies = [
[[package]] [[package]]
name = "kon" name = "kon"
version = "0.3.19" version = "0.3.20"
dependencies = [ dependencies = [
"bb8", "bb8",
"bb8-postgres", "bb8-postgres",
@ -1147,11 +1147,11 @@ dependencies = [
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.7.4" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
dependencies = [ dependencies = [
"adler", "adler2",
] ]
[[package]] [[package]]
@ -1228,9 +1228,9 @@ dependencies = [
[[package]] [[package]]
name = "object" name = "object"
version = "0.36.3" version = "0.36.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a"
dependencies = [ dependencies = [
"memchr", "memchr",
] ]
@ -1264,7 +1264,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -1303,7 +1303,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"redox_syscall 0.5.3", "redox_syscall",
"smallvec", "smallvec",
"windows-targets 0.52.6", "windows-targets 0.52.6",
] ]
@ -1349,7 +1349,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -1396,7 +1396,7 @@ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -1419,9 +1419,9 @@ dependencies = [
[[package]] [[package]]
name = "postgres-types" name = "postgres-types"
version = "0.2.7" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02048d9e032fb3cc3413bbf7b83a15d84a5d419778e2628751896d856498eee9" checksum = "f66ea23a2d0e5734297357705193335e0a957696f34bed2f2faefacb2fec336f"
dependencies = [ dependencies = [
"bytes", "bytes",
"fallible-iterator", "fallible-iterator",
@ -1471,9 +1471,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.36.1" version = "0.36.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96a05e2e8efddfa51a84ca47cec303fac86c8541b686d37cac5efc0e094417bc" checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe"
dependencies = [ dependencies = [
"encoding_rs", "encoding_rs",
"memchr", "memchr",
@ -1481,9 +1481,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.36" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -1540,9 +1540,9 @@ dependencies = [
[[package]] [[package]]
name = "redis" name = "redis"
version = "0.26.1" version = "0.27.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e902a69d09078829137b4a5d9d082e0490393537badd7c91a3d69d14639e115f" checksum = "a7e86f5670bd8b028edfb240f0616cad620705b31ec389d55e4f3da2c38dcd48"
dependencies = [ dependencies = [
"arc-swap", "arc-swap",
"async-trait", "async-trait",
@ -1561,18 +1561,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.4.1" version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" checksum = "0884ad60e090bf1345b93da0a5de8923c93884cd03f40dfcfddd3b4bee661853"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "redox_syscall"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
] ]
@ -1666,7 +1657,7 @@ dependencies = [
"http-body 1.0.1", "http-body 1.0.1",
"http-body-util", "http-body-util",
"hyper 1.4.1", "hyper 1.4.1",
"hyper-rustls 0.27.2", "hyper-rustls 0.27.3",
"hyper-tls", "hyper-tls",
"hyper-util", "hyper-util",
"ipnet", "ipnet",
@ -1682,7 +1673,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_urlencoded", "serde_urlencoded",
"sync_wrapper 1.0.1", "sync_wrapper 1.0.1",
"system-configuration 0.6.0", "system-configuration 0.6.1",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tower-service", "tower-service",
@ -1726,9 +1717,9 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.34" version = "0.38.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"errno", "errno",
@ -1758,20 +1749,20 @@ dependencies = [
"log", "log",
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
"rustls-webpki 0.102.6", "rustls-webpki 0.102.8",
"subtle", "subtle",
"zeroize", "zeroize",
] ]
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.12" version = "0.23.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"rustls-pki-types", "rustls-pki-types",
"rustls-webpki 0.102.6", "rustls-webpki 0.102.8",
"subtle", "subtle",
"zeroize", "zeroize",
] ]
@ -1813,9 +1804,9 @@ dependencies = [
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
version = "0.102.6" version = "0.102.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"
dependencies = [ dependencies = [
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
@ -1839,11 +1830,11 @@ dependencies = [
[[package]] [[package]]
name = "schannel" name = "schannel"
version = "0.1.23" version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" checksum = "e9aaafd5a2b6e3d657ff009d82fbd630b6bd54dd4eb06f21693925cdf80f9b8b"
dependencies = [ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.59.0",
] ]
[[package]] [[package]]
@ -1887,9 +1878,9 @@ dependencies = [
[[package]] [[package]]
name = "security-framework-sys" name = "security-framework-sys"
version = "2.11.1" version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -1906,9 +1897,9 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.208" version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
@ -1924,20 +1915,20 @@ dependencies = [
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.208" version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
name = "serde_json" name = "serde_json"
version = "1.0.125" version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
dependencies = [ dependencies = [
"itoa", "itoa",
"memchr", "memchr",
@ -2130,9 +2121,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.75" version = "2.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2156,9 +2147,9 @@ dependencies = [
[[package]] [[package]]
name = "sysinfo" name = "sysinfo"
version = "0.31.2" version = "0.31.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4115055da5f572fff541dd0c4e61b0262977f453cc9fe04be83aba25a89bdab" checksum = "355dbe4f8799b304b05e1b0f05fc59b2a18d36645cf169607da45bde2f69a1be"
dependencies = [ dependencies = [
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@ -2181,9 +2172,9 @@ dependencies = [
[[package]] [[package]]
name = "system-configuration" name = "system-configuration"
version = "0.6.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bc6ee10a9b4fcf576e9b0819d95ec16f4d2c02d39fd83ac1c8789785c4a42" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
dependencies = [ dependencies = [
"bitflags 2.6.0", "bitflags 2.6.0",
"core-foundation", "core-foundation",
@ -2246,7 +2237,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -2310,9 +2301,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.39.3" version = "1.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
dependencies = [ dependencies = [
"backtrace", "backtrace",
"bytes", "bytes",
@ -2334,7 +2325,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -2349,9 +2340,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-postgres" name = "tokio-postgres"
version = "0.7.11" version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03adcf0147e203b6032c0b2d30be1415ba03bc348901f3ff1cc0df6a733e60c3" checksum = "3b5d3742945bc7d7f210693b0c58ae542c6fd47b17adbbda0885f3dcb34a6bdb"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",
@ -2400,7 +2391,7 @@ version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4"
dependencies = [ dependencies = [
"rustls 0.23.12", "rustls 0.23.13",
"rustls-pki-types", "rustls-pki-types",
"tokio", "tokio",
] ]
@ -2418,14 +2409,14 @@ dependencies = [
"tokio", "tokio",
"tokio-rustls 0.25.0", "tokio-rustls 0.25.0",
"tungstenite", "tungstenite",
"webpki-roots 0.26.3", "webpki-roots 0.26.6",
] ]
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.11" version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-core", "futures-core",
@ -2457,9 +2448,9 @@ dependencies = [
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.22.20" version = "0.22.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" checksum = "3b072cee73c449a636ffd6f32bd8de3a9f7119139aff882f44943ce2986dc5cf"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"serde", "serde",
@ -2515,7 +2506,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -2620,9 +2611,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]] [[package]]
name = "typesize" name = "typesize"
version = "0.1.7" version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb704842c709bc76f63e99e704cb208beeccca2abbabd0d9aec02e48ca1cee0f" checksum = "5dece5c06268af6a9ff4541788601e560a4284ffebfb357f713d676f13b964db"
dependencies = [ dependencies = [
"chrono", "chrono",
"dashmap", "dashmap",
@ -2644,7 +2635,7 @@ checksum = "905e88c2a4cc27686bd57e495121d451f027e441388a67f773be729ad4be1ea8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -2664,15 +2655,15 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.12" version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
[[package]] [[package]]
name = "unicode-normalization" name = "unicode-normalization"
version = "0.1.23" version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956"
dependencies = [ dependencies = [
"tinyvec", "tinyvec",
] ]
@ -2792,7 +2783,7 @@ dependencies = [
"once_cell", "once_cell",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2826,7 +2817,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2868,20 +2859,20 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "0.26.3" version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958"
dependencies = [ dependencies = [
"rustls-pki-types", "rustls-pki-types",
] ]
[[package]] [[package]]
name = "whoami" name = "whoami"
version = "1.5.1" version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a44ab49fad634e88f55bf8f9bb3abd2f27d7204172a112c7c9987e01c1c94ea9" checksum = "372d5b87f58ec45c384ba03563b03544dc5fadc3983e434b286913f5b4a9bb6d"
dependencies = [ dependencies = [
"redox_syscall 0.4.1", "redox_syscall",
"wasite", "wasite",
"web-sys", "web-sys",
] ]
@ -2962,7 +2953,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -2973,7 +2964,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]
@ -3200,7 +3191,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.75", "syn 2.0.77",
] ]
[[package]] [[package]]

View File

@ -1,24 +1,24 @@
[package] [package]
name = "kon" name = "kon"
version = "0.3.19" version = "0.3.20"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
bb8 = "0.8.5" bb8 = "0.8.5"
bb8-postgres = "0.8.1" bb8-postgres = "0.8.1"
bb8-redis = "0.16.0" bb8-redis = "0.17.0"
cargo_toml = "0.20.4" cargo_toml = "0.20.4"
feed-rs = "2.1.0" feed-rs = "2.1.0"
once_cell = "1.19.0" once_cell = "1.19.0"
poise = "0.6.1" poise = "0.6.1"
regex = "1.10.6" regex = "1.10.6"
reqwest = { version = "0.12.7", features = ["json"] } reqwest = { version = "0.12.7", features = ["json"] }
serde = "1.0.208" serde = "1.0.210"
serde_json = "1.0.125" serde_json = "1.0.128"
sysinfo = "0.31.2" sysinfo = "0.31.4"
tokenservice-client = { version = "0.4.0", registry = "gitea" } tokenservice-client = { version = "0.4.0", registry = "gitea" }
tokio = { version = "1.39.3", features = ["macros", "signal", "rt-multi-thread"] } tokio = { version = "1.40.0", features = ["macros", "signal", "rt-multi-thread"] }
tokio-postgres = "0.7.11" tokio-postgres = "0.7.12"
uptime_lib = "0.3.1" uptime_lib = "0.3.1"
[features] [features]

View File

@ -1,24 +1,10 @@
FROM rust:1.80-alpine3.20 AS chef FROM scratch as base
ENV RUSTFLAGS="-C target-feature=-crt-static"
ARG GIT_HASH
ENV GIT_COMMIT_HASH=${GIT_HASH}
RUN apk add --no-cache openssl-dev musl-dev
RUN cargo install cargo-chef
WORKDIR /builder WORKDIR /builder
FROM chef AS planner
COPY . . COPY . .
RUN cargo chef prepare
FROM chef AS builder
COPY --from=planner /builder/recipe.json recipe.json
RUN cargo chef cook --release
COPY . .
RUN cargo build --offline -rF production
FROM alpine:edge FROM alpine:edge
LABEL org.opencontainers.image.source="https://git.toast-server.net/toast/Kon" LABEL org.opencontainers.image.source="https://git.toast-server.net/toast/Kon"
RUN apk add --no-cache libgcc fluidsynth RUN apk add --no-cache libgcc fluidsynth
WORKDIR /kon WORKDIR /kon
COPY --from=builder /builder/target/release/kon . COPY --from=builder /builder/target/x86_64-unknown-linux-musl/release/kon .
CMD [ "./kon" ] CMD [ "./kon" ]

View File

@ -4,7 +4,23 @@ fn main() {
if let Ok(git_commit_hash) = std::env::var("GIT_COMMIT_HASH") { if let Ok(git_commit_hash) = std::env::var("GIT_COMMIT_HASH") {
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", &git_commit_hash[..7]); println!("cargo:rustc-env=GIT_COMMIT_HASH={}", &git_commit_hash[..7]);
} else { } else {
println!("cargo:warning=GIT_COMMIT_HASH not found");
println!("cargo:rustc-env=GIT_COMMIT_HASH=no_env_set"); println!("cargo:rustc-env=GIT_COMMIT_HASH=no_env_set");
} }
} }
{
let git_branch = std::process::Command::new("git")
.args(&["rev-parse", "--abbrev-ref", "HEAD"])
.output()
.expect("Command execution failed");
if git_branch.status.success() {
let git_branch = String::from_utf8(git_branch.stdout).expect("Invalid UTF-8 sequence").trim().to_string();
println!("cargo:rustc-env=GIT_COMMIT_BRANCH={}", &git_branch);
} else {
println!("cargo:warning=GIT_COMMIT_BRANCH not found");
println!("cargo:rustc-env=GIT_COMMIT_BRANCH=no_env_set");
}
}
} }

View File

@ -1,7 +1,7 @@
services: services:
bot: bot:
container_name: kon container_name: kon
#image: git.toast-server.net/toast/kon:main #image: git.toast-server.net/toast/kon:master
build: . build: .
restart: unless-stopped restart: unless-stopped
depends_on: depends_on:
@ -12,17 +12,3 @@ services:
restart: unless-stopped restart: unless-stopped
ports: ports:
- 37935:6379/tcp - 37935:6379/tcp
# db:
# container_name: kon-database
# image: postgres:16.4-alpine3.20
# restart: unless-stopped
# ports:
# - 37930:5432/tcp
# volumes:
# - /var/lib/docker/volumes/kon-database:/var/lib/postgresql/data:rw
# environment:
# TZ: Australia/Sydney
# POSTGRES_USER: ${POSTGRES_USER}
# POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
# POSTGRES_DB: ${POSTGRES_DB}

View File

@ -1,5 +1,18 @@
use crate::Error;
pub mod ilo; pub mod ilo;
pub mod midi; pub mod midi;
pub mod ping; pub mod ping;
pub mod status; pub mod status;
pub mod uptime; pub mod uptime;
/// Deploy the commands globally or in a guild
#[poise::command(
prefix_command,
owners_only,
guild_only
)]
pub async fn deploy(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
poise::builtins::register_application_commands_buttons(ctx).await?;
Ok(())
}

View File

@ -1,10 +1,10 @@
use crate::{ use crate::{
Error, Error,
GIT_COMMIT_HASH, GIT_COMMIT_HASH,
GIT_COMMIT_BRANCH,
internals::utils::{ internals::utils::{
BOT_VERSION, BOT_VERSION,
format_duration, format_duration
concat_message
} }
}; };
@ -70,13 +70,13 @@ pub async fn uptime(ctx: poise::Context<'_, (), Error>) -> Result<(), Error> {
} }
let stat_msg = vec![ let stat_msg = vec![
format!("**{} {}** `{}`", _bot.name, BOT_VERSION.as_str(), GIT_COMMIT_HASH), format!("**{} {}** `{}:{}`", _bot.name, BOT_VERSION.as_str(), GIT_COMMIT_HASH, GIT_COMMIT_BRANCH),
format!(">>> System: `{}`", format_duration(sys_uptime)), format!(">>> System: `{}`", format_duration(sys_uptime)),
format!("Process: `{}`", format_duration(proc_uptime)), format!("Process: `{}`", format_duration(proc_uptime)),
format!("CPU: `{}`", format!("{}", cpu[0].brand())), format!("CPU: `{}`", format!("{}", cpu[0].brand())),
format!("OS: `{}`", get_os_info()) format!("OS: `{}`", get_os_info())
]; ];
ctx.reply(concat_message(stat_msg)).await?; ctx.reply(stat_msg.join("\n")).await?;
Ok(()) Ok(())
} }

View File

@ -1,2 +1 @@
pub mod cache; pub mod cache;
// pub mod database;

View File

@ -1,78 +0,0 @@
use crate::internals::utils::token_path;
use bb8::{Pool, PooledConnection};
use bb8_postgres::PostgresConnectionManager;
use tokio::time::{
Duration,
sleep
};
use tokio_postgres::{
Client,
NoTls,
Error,
config::Config
};
use std::{
ops::Deref,
str::FromStr,
sync::{
Mutex,
LazyLock
}
};
pub static DATABASE: LazyLock<Mutex<Option<DatabaseController>>> = LazyLock::new(|| Mutex::new(None));
pub struct DatabaseController {
pub pool: Pool<PostgresConnectionManager<NoTls>>
}
impl DatabaseController {
pub async fn new() -> Result<(), Error> {
let manager = PostgresConnectionManager::new(Config::from_str(token_path().await.postgres_uri.as_str())?, NoTls);
let pool = bb8::Pool::builder().build(manager).await?;
let err_name = "Postgres[Error]";
let pool_clone = pool.clone();
tokio::spawn(async move {
loop {
match Self::attempt_connect(&pool_clone).await {
Ok(conn) => {
println!("Postgres[Info]: Successfully connected");
let client: &Client = conn.deref();
/* if let Err(e) = client.batch_execute("").await {
eprintln!("{}: {}", err_name, e);
} */ // Uncomment this if bot is going to use a database
},
Err(e) => {
eprintln!("{}: {}", err_name, e);
sleep(Duration::from_secs(5)).await;
}
}
break;
}
});
let controller = Self { pool };
*DATABASE.lock().unwrap() = Some(controller);
Ok(())
}
async fn attempt_connect<'a>(pool: &'a bb8::Pool<PostgresConnectionManager<NoTls>>) -> Result<PooledConnection<'a, PostgresConnectionManager<NoTls>>, bb8::RunError<Error>> {
let mut backoff = 1;
loop {
match pool.get().await {
Ok(conn) => return Ok(conn),
Err(e) => {
eprintln!("Postgres[ConnError]: {}, retrying in {} seconds", e, backoff);
sleep(Duration::from_secs(backoff)).await;
if backoff < 64 {
backoff *= 2;
}
}
}
}
}
}

View File

@ -1,12 +1,10 @@
use std::sync::LazyLock; use std::sync::LazyLock;
pub struct ConfigMeta { pub struct ConfigMeta {
// pub guild_id: u64,
pub embed_color: i32, pub embed_color: i32,
pub ready_notify: u64, pub ready_notify: u64,
pub rss_channel: u64, pub rss_channel: u64,
pub kon_logs: u64, pub kon_logs: u64,
pub deploy_commands: bool,
pub developers: Vec<u64> pub developers: Vec<u64>
} }
@ -16,22 +14,18 @@ pub static BINARY_PROPERTIES: LazyLock<ConfigMeta> = LazyLock::new(|| ConfigMeta
#[cfg(not(feature = "production"))] #[cfg(not(feature = "production"))]
pub static BINARY_PROPERTIES: LazyLock<ConfigMeta> = LazyLock::new(|| pub static BINARY_PROPERTIES: LazyLock<ConfigMeta> = LazyLock::new(||
ConfigMeta::new() ConfigMeta::new()
// .guild_id(865673694184996885)
.embed_color(0xf1d63c) .embed_color(0xf1d63c)
.ready_notify(865673694184996888) .ready_notify(865673694184996888)
.rss_channel(865673694184996888) .rss_channel(865673694184996888)
.deploy_commands(false)
); );
impl ConfigMeta { impl ConfigMeta {
fn new() -> Self { fn new() -> Self {
Self { Self {
// guild_id: 865673694184996885,
embed_color: 0x5a99c7, embed_color: 0x5a99c7,
ready_notify: 865673694184996888, ready_notify: 865673694184996888,
rss_channel: 865673694184996888, rss_channel: 865673694184996888,
kon_logs: 1268493237912604672, kon_logs: 1268493237912604672,
deploy_commands: false,
developers: vec![ developers: vec![
190407856527376384 // toast.ts 190407856527376384 // toast.ts
] ]
@ -39,12 +33,6 @@ impl ConfigMeta {
} }
// Scalable functions below; // Scalable functions below;
/* #[cfg(not(feature = "production"))]
fn guild_id(mut self, guild_id: u64) -> Self {
self.guild_id = guild_id;
self
} */
#[cfg(not(feature = "production"))] #[cfg(not(feature = "production"))]
fn embed_color(mut self, color: i32) -> Self { fn embed_color(mut self, color: i32) -> Self {
self.embed_color = color; self.embed_color = color;
@ -62,10 +50,4 @@ impl ConfigMeta {
self.rss_channel = channel_id; self.rss_channel = channel_id;
self self
} }
#[cfg(not(feature = "production"))]
fn deploy_commands(mut self, deploy: bool) -> Self {
self.deploy_commands = deploy;
self
}
} }

View File

@ -1,9 +1,47 @@
pub mod rss; mod rss;
pub use rss::rss;
use tokio::task::spawn;
use poise::serenity_prelude::Context;
use std::{
sync::{
Arc,
atomic::{
AtomicBool,
Ordering
}
},
future::Future
};
fn task_info(name: &str, message: &str) { fn task_info(name: &str, message: &str) {
println!("{}", format!("TaskScheduler[{}]: {}", name, message)); println!("{}", format!("TaskScheduler[{}]: {}", name, message))
} }
fn task_err(name: &str, message: &str) { fn task_err(name: &str, message: &str) {
eprintln!("{}", format!("TaskScheduler[{}:Error]: {}", name, message)); eprintln!("{}", format!("TaskScheduler[{}:Error]: {}", name, message))
}
static TASK_RUNNING: AtomicBool = AtomicBool::new(false);
pub async fn run_task<F, T>(ctx: Arc<Context>, task: F)
where
F: Fn(Arc<Context>) -> T + Send + 'static,
T: Future<Output = Result<(), crate::Error>> + Send + 'static
{
let ctx_cl = Arc::clone(&ctx);
if !TASK_RUNNING.load(Ordering::SeqCst) {
TASK_RUNNING.store(true, Ordering::SeqCst);
spawn(async move {
if let Err(y) = task(ctx_cl).await {
eprintln!("TaskScheduler[Main:Error]: Failed to execute the task, error reason: {}", y);
if let Some(source) = y.source() {
eprintln!("TaskScheduler[Main:Error]: Failed to execute the task, this is caused by: {:#?}", source);
}
}
TASK_RUNNING.store(false, Ordering::SeqCst);
});
}
} }

View File

@ -18,13 +18,58 @@ use poise::serenity_prelude::{
Context, Context,
ChannelId, ChannelId,
EditMessage, EditMessage,
CreateMessage CreateMessage,
CreateEmbed,
}; };
// This is for building up the embed with the feed data // This is for building up the embed with the feed data
/* std::fs::File::create("rss_name.log").unwrap(); /* std::fs::File::create("rss_name.log").unwrap();
std::fs::write("rss_name.log", format!("{:#?}", feed))?; */ std::fs::write("rss_name.log", format!("{:#?}", feed))?; */
// todo; have a reusable function for feeding RSS data and building the embed out of it.
// see github.rs / esxi.rs / gportal.rs for references of this idea.
async fn process_embed(
ctx: &Context,
embed: Option<CreateEmbed>,
redis_key: &str,
content_key: &str
) -> Result<(), crate::Error> {
if let Some(embed) = embed {
let redis = get_redis().await;
let channel = ChannelId::new(BINARY_PROPERTIES.rss_channel);
let msg_id_key: Option<String> = redis.get(redis_key).await?;
let cached_content: Option<String> = redis.get(content_key).await.unwrap_or(None);
if let Some(msg_id_key) = msg_id_key {
if let Ok(msg_id) = msg_id_key.parse::<u64>() {
if let Ok(mut message) = channel.message(&ctx.http, msg_id).await {
let new_description = message.embeds[0].description.clone().unwrap();
if cached_content.as_deref() != Some(&new_description) {
message.edit(&ctx.http, EditMessage::new().embed(embed)).await?;
}
sleep(Duration::from_secs(15)).await;
if Regex::new(r"(?i)\bresolved\b").unwrap().is_match(&new_description) {
message.reply(&ctx.http, "This incident has been marked as resolved!").await?;
redis.del(redis_key).await?;
}
}
}
} else {
let message = channel.send_message(&ctx.http, CreateMessage::new().add_embed(embed)).await?;
redis.set(redis_key, &message.id.to_string()).await?;
redis.expire(redis_key, 36000).await?;
}
}
Ok(())
}
pub async fn feed_processor(ctx: &Context) { pub async fn feed_processor(ctx: &Context) {
let mut log_msgs: Vec<String> = Vec::new(); let mut log_msgs: Vec<String> = Vec::new();
@ -40,45 +85,7 @@ pub async fn feed_processor(ctx: &Context) {
} }
match gportal_embed().await { match gportal_embed().await {
Ok(Some(embed)) => { Ok(Some(embed)) => process_embed(&ctx, Some(embed), "RSS_GPortal_MsgID", "RSS_GPortal_Content").await.unwrap(),
let redis = get_redis().await;
let rkey = "RSS_GPortal_MsgID";
let channel = ChannelId::new(BINARY_PROPERTIES.rss_channel);
// Check if the message ID is in Redis
match redis.get(&rkey).await {
Ok(Some(msg_id_key)) => {
// Fetch the cached content
let cached_content: Option<String> = redis.get("RSS_GPortal_Content").await.unwrap_or(None);
if let Ok(msg_id) = msg_id_key.parse::<u64>() {
// Attempt to edit the message
if let Ok(mut message) = channel.message(&ctx.http, msg_id).await {
let new_desc = message.embeds[0].description.clone().unwrap();
if cached_content.as_deref() != Some(&new_desc) {
message.edit(&ctx.http, EditMessage::new().embed(embed)).await.unwrap();
}
sleep(Duration::from_secs(25)).await;
if Regex::new(r"(?i)\bresolved\b").unwrap().is_match(&new_desc) {
message.reply(&ctx.http, "This incident has been marked as resolved!").await.unwrap();
redis.del(&rkey).await.unwrap();
}
}
}
},
Ok(None) | Err(_) => {
// If the message is invalid ID, send a new message instead
let message = channel.send_message(&ctx.http, CreateMessage::new()
.content("*Uh-oh! G-Portal is having issues!*").add_embed(embed)
).await.unwrap();
redis.set(&rkey, &message.id.to_string()).await.unwrap();
redis.expire(&rkey, 36000).await.unwrap();
}
}
},
Ok(None) => (), Ok(None) => (),
Err(y) => { Err(y) => {
log_msgs.push(format!("**[{TASK_NAME}:GPortal:Error]:** Feed failed with the following error:```\n{}\n```", y)); log_msgs.push(format!("**[{TASK_NAME}:GPortal:Error]:** Feed failed with the following error:```\n{}\n```", y));
@ -87,43 +94,7 @@ pub async fn feed_processor(ctx: &Context) {
} }
match github_embed().await { match github_embed().await {
Ok(Some(embed)) => { Ok(Some(embed)) => process_embed(&ctx, Some(embed), "RSS_GitHub_MsgID", "RSS_GitHub_Content").await.unwrap(),
let redis = get_redis().await;
let rkey = "RSS_GitHub_MsgID";
let channel = ChannelId::new(BINARY_PROPERTIES.rss_channel);
// Check if the message ID is in Redis
match redis.get(&rkey).await {
Ok(Some(msg_id_key)) => {
// Fetch the cached content
let cached_content: Option<String> = redis.get("RSS_GitHub_Content").await.unwrap_or(None);
if let Ok(msg_id) = msg_id_key.parse::<u64>() {
// Attempt to edit the message
if let Ok(mut message) = channel.message(&ctx.http, msg_id).await {
let new_desc = message.embeds[0].description.clone().unwrap();
if cached_content.as_deref() != Some(&new_desc) {
message.edit(&ctx.http, EditMessage::new().embed(embed)).await.unwrap();
}
sleep(Duration::from_secs(25)).await;
if Regex::new(r"(?i)\bresolved\b").unwrap().is_match(&new_desc) {
message.reply(&ctx.http, "This incident has been marked as resolved!").await.unwrap();
redis.del(&rkey).await.unwrap();
}
}
}
},
Ok(None) | Err(_) => {
// If the message is not found, send a new message instead
let message = channel.send_message(&ctx.http, CreateMessage::new().add_embed(embed)).await.unwrap();
redis.set(&rkey, &message.id.to_string()).await.unwrap();
redis.expire(&rkey, 36000).await.unwrap();
}
}
},
Ok(None) => (), Ok(None) => (),
Err(y) => { Err(y) => {
log_msgs.push(format!("**[{TASK_NAME}:GitHub:Error]:** Feed failed with the following error:```\n{}\n```", y)); log_msgs.push(format!("**[{TASK_NAME}:GitHub:Error]:** Feed failed with the following error:```\n{}\n```", y));

View File

@ -20,10 +20,6 @@ pub async fn token_path() -> TokenServiceApi {
TSCLIENT.lock().await.get().await.unwrap() TSCLIENT.lock().await.get().await.unwrap()
} }
pub fn concat_message(messages: Vec<String>) -> String {
messages.join("\n")
}
pub fn mention_dev(ctx: poise::Context<'_, (), crate::Error>) -> Option<String> { pub fn mention_dev(ctx: poise::Context<'_, (), crate::Error>) -> Option<String> {
let devs = super::config::BINARY_PROPERTIES.developers.clone(); let devs = super::config::BINARY_PROPERTIES.developers.clone();
let app_owners = ctx.framework().options().owners.clone(); let app_owners = ctx.framework().options().owners.clone();

View File

@ -4,27 +4,22 @@ mod internals;
// https://cdn.toast-server.net/RustFSHiearchy.png // https://cdn.toast-server.net/RustFSHiearchy.png
// Using the new filesystem hierarchy // Using the new filesystem hierarchy
use crate::{ use crate::internals::{
internals::{ utils::{
utils::{ BOT_VERSION,
BOT_VERSION, token_path,
token_path, mention_dev
mention_dev
},
config::BINARY_PROPERTIES
}, },
// controllers::database::DatabaseController tasks::{
run_task,
rss
},
config::BINARY_PROPERTIES
}; };
use std::{ use std::{
thread::current, sync::Arc,
sync::{ thread::current
Arc,
atomic::{
AtomicBool,
Ordering
}
}
}; };
use poise::serenity_prelude::{ use poise::serenity_prelude::{
builder::{ builder::{
@ -37,22 +32,22 @@ use poise::serenity_prelude::{
FullEvent, FullEvent,
ClientBuilder, ClientBuilder,
ChannelId, ChannelId,
Command,
GatewayIntents GatewayIntents
}; };
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
static TASK_RUNNING: AtomicBool = AtomicBool::new(false);
#[cfg(feature = "production")] #[cfg(feature = "production")]
pub static GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH"); pub static GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
pub static GIT_COMMIT_BRANCH: &str = env!("GIT_COMMIT_BRANCH");
#[cfg(not(feature = "production"))] #[cfg(not(feature = "production"))]
pub static GIT_COMMIT_HASH: &str = "devel"; pub static GIT_COMMIT_HASH: &str = "devel";
async fn on_ready( async fn on_ready(
ctx: &Context, ctx: &Context,
ready: &Ready, ready: &Ready,
framework: &poise::Framework<(), Error> _framework: &poise::Framework<(), Error>
) -> Result<(), Error> { ) -> Result<(), Error> {
#[cfg(not(feature = "production"))] #[cfg(not(feature = "production"))]
{ {
@ -62,7 +57,7 @@ async fn on_ready(
println!("Event[Ready][Notice]: Session limit: {}/{}", session.remaining, session.total); println!("Event[Ready][Notice]: Session limit: {}/{}", session.remaining, session.total);
} }
println!("Event[Ready]: Build version: {} ({})", BOT_VERSION.to_string(), GIT_COMMIT_HASH); println!("Event[Ready]: Build version: {} ({}:{})", BOT_VERSION.to_string(), GIT_COMMIT_HASH, GIT_COMMIT_BRANCH);
println!("Event[Ready]: Connected to API as {}", ready.user.name); println!("Event[Ready]: Connected to API as {}", ready.user.name);
let message = CreateMessage::new(); let message = CreateMessage::new();
@ -73,88 +68,22 @@ async fn on_ready(
ChannelId::new(BINARY_PROPERTIES.ready_notify).send_message(&ctx.http, message.add_embed(ready_embed)).await?; ChannelId::new(BINARY_PROPERTIES.ready_notify).send_message(&ctx.http, message.add_embed(ready_embed)).await?;
if BINARY_PROPERTIES.deploy_commands {
let builder = poise::builtins::create_application_commands(&framework.options().commands);
let commands = Command::set_global_commands(&ctx.http, builder).await;
let mut commands_deployed = std::collections::HashSet::new();
match commands {
Ok(cmdmap) => for command in cmdmap.iter() {
commands_deployed.insert(command.name.clone());
},
Err(y) => eprintln!("Error registering commands: {:?}", y)
}
if commands_deployed.len() > 0 {
println!("Event[Ready]: Deployed the commands globally:\n- {}", commands_deployed.into_iter().collect::<Vec<_>>().join("\n- "));
}
}
Ok(()) Ok(())
} }
async fn event_processor( async fn event_processor(
ctx: &Context, ctx: &Context,
event: &FullEvent, event: &FullEvent,
framework: poise::FrameworkContext<'_, (), Error> _framework: poise::FrameworkContext<'_, (), Error>
) -> Result<(), Error> { ) -> Result<(), Error> {
match event { match event {
FullEvent::Ratelimit { data } => {
println!("Event[Ratelimit]: {:#?}", data);
}
FullEvent::Message { new_message } => {
if new_message.author.bot || !new_message.guild_id.is_none() {
return Ok(());
}
if new_message.content.to_lowercase().starts_with("deploy") && new_message.author.id == BINARY_PROPERTIES.developers[0] {
let builder = poise::builtins::create_application_commands(&framework.options().commands);
let commands = Command::set_global_commands(&ctx.http, builder).await;
let mut commands_deployed = std::collections::HashSet::new();
match commands {
Ok(cmdmap) => for command in cmdmap.iter() {
commands_deployed.insert(command.name.clone());
},
Err(y) => {
eprintln!("Error registering commands: {:?}", y);
new_message.reply(&ctx.http, "Deployment failed, check console for more details!").await?;
}
}
if commands_deployed.len() > 0 {
new_message.reply(&ctx.http, format!(
"Deployed the commands globally:\n- {}",
commands_deployed.into_iter().collect::<Vec<_>>().join("\n- ")
)).await?;
}
}
}
FullEvent::Ready { .. } => { FullEvent::Ready { .. } => {
let thread_id = format!("{:?}", current().id()); let thread_id = format!("{:?}", current().id());
let thread_num: String = thread_id.chars().filter(|c| c.is_digit(10)).collect(); let thread_num: String = thread_id.chars().filter(|c| c.is_digit(10)).collect();
println!("Event[Ready]: Task Scheduler operating on thread {}", thread_num); println!("Event[Ready]: Task Scheduler operating on thread {}", thread_num);
let ctx = Arc::new(ctx.clone()); let ctx = Arc::new(ctx.clone());
run_task(ctx.clone(), rss).await;
if !TASK_RUNNING.load(Ordering::SeqCst) {
TASK_RUNNING.store(true, Ordering::SeqCst);
tokio::spawn(async move {
match internals::tasks::rss::rss(ctx).await {
Ok(_) => {},
Err(y) => {
eprintln!("TaskScheduler[Main:RSS:Error]: Task execution failed: {}", y);
if let Some(source) = y.source() {
eprintln!("TaskScheduler[Main:RSS:Error]: Task execution failed caused by: {:#?}", source);
}
}
}
TASK_RUNNING.store(false, Ordering::SeqCst);
});
} else {
println!("TaskScheduler[Main:RSS:Notice]: Another thread is already running this task, ignoring");
}
} }
_ => {} _ => {}
} }
@ -164,17 +93,24 @@ async fn event_processor(
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
// DatabaseController::new().await.expect("Error initializing database");
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
commands: vec![ commands: vec![
commands::deploy(),
commands::ilo::ilo(), commands::ilo::ilo(),
commands::ping::ping(), commands::ping::ping(),
commands::status::status(), commands::status::status(),
commands::midi::midi_to_wav(), commands::midi::midi_to_wav(),
commands::uptime::uptime() commands::uptime::uptime()
], ],
prefix_options: poise::PrefixFrameworkOptions {
prefix: Some(String::from("konata")),
mention_as_prefix: false,
case_insensitive_commands: true,
ignore_bots: true,
ignore_thread_creation: true,
..Default::default()
},
pre_command: |ctx| Box::pin(async move { pre_command: |ctx| Box::pin(async move {
let get_guild_name = match ctx.guild() { let get_guild_name = match ctx.guild() {
Some(guild) => guild.name.clone(), Some(guild) => guild.name.clone(),
@ -211,8 +147,8 @@ async fn main() {
let mut client = ClientBuilder::new( let mut client = ClientBuilder::new(
token_path().await.main, token_path().await.main,
GatewayIntents::GUILDS GatewayIntents::GUILDS
| GatewayIntents::GUILD_MESSAGES
| GatewayIntents::MESSAGE_CONTENT | GatewayIntents::MESSAGE_CONTENT
| GatewayIntents::DIRECT_MESSAGES
) )
.framework(framework) .framework(framework)
.await.expect("Error creating client"); .await.expect("Error creating client");