Compare commits

..

12 Commits

16 changed files with 1382 additions and 848 deletions

350
Cargo.lock generated
View File

@@ -562,9 +562,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "bytes"
version = "1.11.0"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b35204fbdc0b3f4446b89fc1ac2cf84a8a68971995d0bf2e925ec7cd960f9cb3"
checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
[[package]]
name = "cacache"
@@ -663,12 +663,6 @@ dependencies = [
"shlex",
]
[[package]]
name = "cesu8"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cfg-if"
version = "1.0.4"
@@ -1601,6 +1595,35 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "ext-trait"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccef4f53516d7589a8ed95216b6ebc9d519df033c1303b42125bfe57aa475d23"
dependencies = [
"ext-trait-proc_macros",
]
[[package]]
name = "ext-trait-proc_macros"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "025e48a9a5db92b84dbd3b6be37853a0e60c1ce9c7c03c08e6ac282766f3e3f0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.111",
]
[[package]]
name = "extension-traits"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7dae1256e3fea2900e1e674bae228edc852f5ce9ccb1c916a496a33cb9bc4cb"
dependencies = [
"ext-trait",
]
[[package]]
name = "fastpool"
version = "1.1.0"
@@ -1700,12 +1723,15 @@ version = "0.1.0"
dependencies = [
"async-compression",
"async-trait",
"bytes",
"capnp",
"capnpc",
"clap",
"dashmap 6.1.0",
"extension-traits",
"futures",
"hound",
"moka",
"opendal",
"opus2",
"patricia_tree 0.10.1",
@@ -1718,6 +1744,8 @@ dependencies = [
"time",
"tokio",
"tokio-util",
"tokio-websockets 0.11.4",
"tokio-websockets 0.13.2",
"tracing",
"tracing-subscriber",
"twilight-gateway",
@@ -1725,6 +1753,7 @@ dependencies = [
"twilight-model",
"twilight-util",
"typed-builder 0.23.2",
"yoke",
]
[[package]]
@@ -2773,50 +2802,6 @@ dependencies = [
"jiff-tzdb",
]
[[package]]
name = "jni"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
dependencies = [
"cesu8",
"cfg-if",
"combine",
"jni-sys 0.3.1",
"log",
"thiserror 1.0.69",
"walkdir",
"windows-sys 0.45.0",
]
[[package]]
name = "jni-sys"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258"
dependencies = [
"jni-sys 0.4.1",
]
[[package]]
name = "jni-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2"
dependencies = [
"jni-sys-macros",
]
[[package]]
name = "jni-sys-macros"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264"
dependencies = [
"quote",
"syn 2.0.111",
]
[[package]]
name = "jobserver"
version = "0.1.34"
@@ -3414,9 +3399,9 @@ dependencies = [
[[package]]
name = "moka"
version = "0.12.12"
version = "0.12.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3dec6bd31b08944e08b58fd99373893a6c17054d6f3ea5006cc894f4f4eee2a"
checksum = "957228ad12042ee839f93c8f257b62b4c0ab5eaae1d4fa60de53b27c9d7c5046"
dependencies = [
"async-lock",
"crossbeam-channel",
@@ -3673,7 +3658,7 @@ checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "opendal"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"ctor",
"opendal-core",
@@ -3719,7 +3704,7 @@ dependencies = [
[[package]]
name = "opendal-core"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"anyhow",
"base64 0.22.1",
@@ -3735,7 +3720,7 @@ dependencies = [
"percent-encoding",
"quick-xml 0.38.4",
"reqsign-core",
"reqwest 0.13.2",
"reqwest",
"serde",
"serde_json",
"tokio",
@@ -3747,7 +3732,7 @@ dependencies = [
[[package]]
name = "opendal-layer-concurrent-limit"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"futures",
"http",
@@ -3758,7 +3743,7 @@ dependencies = [
[[package]]
name = "opendal-layer-logging"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"log",
"opendal-core",
@@ -3767,7 +3752,7 @@ dependencies = [
[[package]]
name = "opendal-layer-retry"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"backon",
"log",
@@ -3777,7 +3762,7 @@ dependencies = [
[[package]]
name = "opendal-layer-timeout"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"opendal-core",
"tokio",
@@ -3786,7 +3771,7 @@ dependencies = [
[[package]]
name = "opendal-service-aliyun-drive"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3800,7 +3785,7 @@ dependencies = [
[[package]]
name = "opendal-service-alluxio"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3813,7 +3798,7 @@ dependencies = [
[[package]]
name = "opendal-service-azblob"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"base64 0.22.1",
"bytes",
@@ -3833,7 +3818,7 @@ dependencies = [
[[package]]
name = "opendal-service-azdls"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3851,7 +3836,7 @@ dependencies = [
[[package]]
name = "opendal-service-azfile"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3868,7 +3853,7 @@ dependencies = [
[[package]]
name = "opendal-service-azure-common"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"http",
"opendal-core",
@@ -3877,7 +3862,7 @@ dependencies = [
[[package]]
name = "opendal-service-b2"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3891,7 +3876,7 @@ dependencies = [
[[package]]
name = "opendal-service-cacache"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"cacache",
@@ -3902,7 +3887,7 @@ dependencies = [
[[package]]
name = "opendal-service-d1"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3914,7 +3899,7 @@ dependencies = [
[[package]]
name = "opendal-service-dashmap"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"dashmap 6.1.0",
"log",
@@ -3925,7 +3910,7 @@ dependencies = [
[[package]]
name = "opendal-service-dbfs"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"base64 0.22.1",
"bytes",
@@ -3939,7 +3924,7 @@ dependencies = [
[[package]]
name = "opendal-service-dropbox"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -3952,7 +3937,7 @@ dependencies = [
[[package]]
name = "opendal-service-etcd"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"etcd-client",
"fastpool",
@@ -3964,7 +3949,7 @@ dependencies = [
[[package]]
name = "opendal-service-fs"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"log",
@@ -3977,7 +3962,7 @@ dependencies = [
[[package]]
name = "opendal-service-ftp"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"fastpool",
@@ -3995,7 +3980,7 @@ dependencies = [
[[package]]
name = "opendal-service-gcs"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"async-trait",
"bytes",
@@ -4015,7 +4000,7 @@ dependencies = [
[[package]]
name = "opendal-service-gdrive"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -4029,7 +4014,7 @@ dependencies = [
[[package]]
name = "opendal-service-ghac"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"ghac",
@@ -4048,7 +4033,7 @@ dependencies = [
[[package]]
name = "opendal-service-github"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"base64 0.22.1",
"bytes",
@@ -4062,7 +4047,7 @@ dependencies = [
[[package]]
name = "opendal-service-gridfs"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"futures",
"mea",
@@ -4074,7 +4059,7 @@ dependencies = [
[[package]]
name = "opendal-service-hdfs-native"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"futures",
@@ -4087,7 +4072,7 @@ dependencies = [
[[package]]
name = "opendal-service-ipmfs"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -4100,7 +4085,7 @@ dependencies = [
[[package]]
name = "opendal-service-mini-moka"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"log",
"mini-moka",
@@ -4111,7 +4096,7 @@ dependencies = [
[[package]]
name = "opendal-service-moka"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"log",
"moka",
@@ -4122,7 +4107,7 @@ dependencies = [
[[package]]
name = "opendal-service-mongodb"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"mea",
"mongodb",
@@ -4133,7 +4118,7 @@ dependencies = [
[[package]]
name = "opendal-service-mysql"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"mea",
"opendal-core",
@@ -4144,7 +4129,7 @@ dependencies = [
[[package]]
name = "opendal-service-pcloud"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"http",
@@ -4157,7 +4142,7 @@ dependencies = [
[[package]]
name = "opendal-service-persy"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"opendal-core",
"persy",
@@ -4167,7 +4152,7 @@ dependencies = [
[[package]]
name = "opendal-service-postgresql"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"mea",
"opendal-core",
@@ -4178,7 +4163,7 @@ dependencies = [
[[package]]
name = "opendal-service-redb"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"opendal-core",
"redb",
@@ -4188,7 +4173,7 @@ dependencies = [
[[package]]
name = "opendal-service-redis"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"bytes",
"fastpool",
@@ -4202,7 +4187,7 @@ dependencies = [
[[package]]
name = "opendal-service-s3"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"base64 0.22.1",
"bytes",
@@ -4222,7 +4207,7 @@ dependencies = [
[[package]]
name = "opendal-service-sled"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"opendal-core",
"serde",
@@ -4232,7 +4217,7 @@ dependencies = [
[[package]]
name = "opendal-service-webdav"
version = "0.55.0"
source = "git+https://github.com/apache/opendal#2f3b9807fcc7f5bd94edfd9a529be526b75ed459"
source = "git+https://github.com/apache/opendal?rev=ecf840b04afd2be109830b9978ba89759adfee79#ecf840b04afd2be109830b9978ba89759adfee79"
dependencies = [
"anyhow",
"bytes",
@@ -4922,7 +4907,6 @@ version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31"
dependencies = [
"aws-lc-rs",
"bytes",
"getrandom 0.3.4",
"lru-slab",
@@ -4954,9 +4938,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.42"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
dependencies = [
"proc-macro2",
]
@@ -5336,49 +5320,11 @@ dependencies = [
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams 0.4.2",
"wasm-streams",
"web-sys",
"webpki-roots 1.0.4",
]
[[package]]
name = "reqwest"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab3f43e3283ab1488b624b44b0e988d0acea0b3214e694730a055cb6b2efa801"
dependencies = [
"base64 0.22.1",
"bytes",
"futures-core",
"futures-util",
"http",
"http-body",
"http-body-util",
"hyper",
"hyper-rustls",
"hyper-util",
"js-sys",
"log",
"percent-encoding",
"pin-project-lite",
"quinn",
"rustls 0.23.35",
"rustls-pki-types",
"rustls-platform-verifier",
"sync_wrapper",
"tokio",
"tokio-rustls 0.26.4",
"tokio-util",
"tower",
"tower-http",
"tower-service",
"url",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-streams 0.5.0",
"web-sys",
]
[[package]]
name = "resolv-conf"
version = "0.7.6"
@@ -5604,33 +5550,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "rustls-platform-verifier"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d99feebc72bae7ab76ba994bb5e121b8d83d910ca40b36e0921f53becc41784"
dependencies = [
"core-foundation",
"core-foundation-sys",
"jni",
"log",
"once_cell",
"rustls 0.23.35",
"rustls-native-certs",
"rustls-platform-verifier-android",
"rustls-webpki 0.103.8",
"security-framework",
"security-framework-sys",
"webpki-root-certs",
"windows-sys 0.61.2",
]
[[package]]
name = "rustls-platform-verifier-android"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f"
[[package]]
name = "rustls-webpki"
version = "0.102.8"
@@ -5941,7 +5860,7 @@ dependencies = [
"futures",
"mime_guess",
"percent-encoding",
"reqwest 0.12.28",
"reqwest",
"secrecy 0.8.0",
"serde",
"serde_cow",
@@ -6204,7 +6123,7 @@ dependencies = [
"parking_lot 0.12.5",
"pin-project",
"rand 0.9.2",
"reqwest 0.12.28",
"reqwest",
"ringbuf",
"rubato",
"rusty_pool",
@@ -6489,7 +6408,7 @@ dependencies = [
"futures-util",
"hls_m3u8",
"patricia_tree 0.8.0",
"reqwest 0.12.28",
"reqwest",
"tokio",
"tracing",
"url",
@@ -6980,6 +6899,7 @@ dependencies = [
"tokio",
"tokio-rustls 0.26.4",
"tokio-util",
"webpki-roots 0.26.11",
]
[[package]]
@@ -7693,19 +7613,6 @@ dependencies = [
"web-sys",
]
[[package]]
name = "wasm-streams"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1ec4f6517c9e11ae630e200b2b65d193279042e28edd4a2cda233e46670bbb"
dependencies = [
"futures-util",
"js-sys",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]]
name = "wasmparser"
version = "0.244.0"
@@ -7738,15 +7645,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "webpki-root-certs"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "804f18a4ac2676ffb4e8b5b5fa9ae38af06df08162314f96a68d2a363e21a8ca"
dependencies = [
"rustls-pki-types",
]
[[package]]
name = "webpki-roots"
version = "0.26.11"
@@ -7923,15 +7821,6 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
"windows-targets 0.42.2",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
@@ -7968,21 +7857,6 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
"windows_aarch64_gnullvm 0.42.2",
"windows_aarch64_msvc 0.42.2",
"windows_i686_gnu 0.42.2",
"windows_i686_msvc 0.42.2",
"windows_x86_64_gnu 0.42.2",
"windows_x86_64_gnullvm 0.42.2",
"windows_x86_64_msvc 0.42.2",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
@@ -8040,12 +7914,6 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
@@ -8064,12 +7932,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
@@ -8088,12 +7950,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
[[package]]
name = "windows_i686_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
@@ -8124,12 +7980,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
[[package]]
name = "windows_i686_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
@@ -8148,12 +7998,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
@@ -8172,12 +8016,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
@@ -8196,12 +8034,6 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
@@ -8369,9 +8201,9 @@ checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
[[package]]
name = "yoke"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca"
dependencies = [
"stable_deref_trait",
"yoke-derive",
@@ -8380,9 +8212,9 @@ dependencies = [
[[package]]
name = "yoke-derive"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e"
dependencies = [
"proc-macro2",
"quote",

View File

@@ -6,12 +6,15 @@ edition = "2024"
[dependencies]
async-compression = { version = "0.4.41", features = ["brotli", "futures-io"] }
async-trait = "0.1.89"
bytes = "1.11.1"
capnp = "0.25.3"
clap = { version = "4.5.40", features = ["derive", "env"] }
dashmap = "6.1.0"
extension-traits = "2.0.2"
futures = "0.3.32"
hound = "3.5.1"
opendal = { git = "https://github.com/apache/opendal", features = [
moka = { version = "0.12.15", features = ["future"] }
opendal = { git = "https://github.com/apache/opendal", rev = "ecf840b04afd2be109830b9978ba89759adfee79", features = [
"services-azfile",
"services-aliyun-drive",
"services-alluxio",
@@ -64,11 +67,24 @@ songbird = { version = "0.6.0", default-features = false, features = [
] }
strum = { version = "0.28.0", features = ["derive"] }
time = "0.3.47"
tokio = { version = "1.46.0", features = ["rt-multi-thread", "macros", "signal"] }
tokio-util = "0.7.18"
tokio = { version = "1.46.0", features = [
"rt-multi-thread",
"macros",
"signal",
] }
tokio-util = { version = "0.7.18", features = ["io"] }
tokio-websockets-0-13 = { package = "tokio-websockets", version = "0.13", features = [
"rustls-webpki-roots",
] }
tokio-websockets-0-11 = { package = "tokio-websockets", version = "0.11", features = [
"rustls-webpki-roots",
] }
tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
twilight-gateway = { version = "0.17", default-features = false, features = ["rustls-webpki-roots", "twilight-http"] }
twilight-gateway = { version = "0.17", default-features = false, features = [
"rustls-webpki-roots",
"twilight-http",
] }
twilight-http = { version = "0.17", default-features = false, features = [
"rustls-webpki-roots",
"hickory",
@@ -77,6 +93,7 @@ twilight-http = { version = "0.17", default-features = false, features = [
twilight-model = "0.17"
twilight-util = { version = "0.17", features = ["builder"] }
typed-builder = "0.23.2"
yoke = "0.8.2"
[build-dependencies]
capnpc = "0.25.3"

175
src/bot_data.rs Normal file
View File

@@ -0,0 +1,175 @@
use async_compression::futures::{bufread::BrotliDecoder, write::BrotliEncoder};
use capnp::message::TypedBuilder;
use futures::{AsyncReadExt, AsyncWriteExt};
use opendal::Operator;
use snafu::{ResultExt as _, Snafu};
use crate::{OperatorExt, bot_capnp, option_ext::OptionExt as _};
#[derive(Debug, Clone)]
pub struct BotDataManager {
operator: Operator,
}
impl BotDataManager {
pub fn new(operator: Operator) -> Self {
Self { operator }
}
}
const PATH: &str = "data.bin.brotli";
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum WithError {
/// couldn't read data for this bot from the storage operator
ReadError { source: opendal::Error },
/// couldn't decompress the bot data from storage
DecompressionError { source: std::io::Error },
/// couldn't deserialize the bot data
DeserializeError { source: capnp::Error },
}
impl BotDataManager {
pub async fn with<R>(
&self,
f: impl FnOnce(bot_capnp::bot::Reader<'_>) -> R,
) -> Result<R, WithError> {
let compressed_buffer = self
.operator
.async_reader_if_exists(PATH)
.await
.context(with_error::ReadSnafu)?;
let decompressed_reader = compressed_buffer.map(BrotliDecoder::new);
let decompressed = decompressed_reader
.map_async(|mut reader| async move {
let mut vec = Vec::new();
reader.read_to_end(&mut vec).await?;
Ok(vec)
})
.await
.transpose()
.context(with_error::DecompressionSnafu)?;
let mut message = TypedBuilder::<bot_capnp::bot::Owned>::new_default();
let fallback = message.init_root();
let mut bot_data = fallback.into_reader();
let message_reader;
if let Some(mut bytes) = decompressed.as_deref() {
message_reader = capnp::serialize::read_message_from_flat_slice_no_alloc(
&mut bytes,
Default::default(),
)
.context(with_error::DeserializeSnafu)?;
bot_data = message_reader
.get_root()
.context(with_error::DeserializeSnafu)?;
}
Ok(f(bot_data))
}
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum UpdateError {
/// couldn't read data for this bot from the storage operator
ReadError { source: opendal::Error },
/// couldn't decompress the bot data from storage
DecompressionError { source: std::io::Error },
/// couldn't deserialize the bot data
DeserializeError { source: capnp::Error },
/// couldn't serialize the (modified) bot data
SerializeError { source: capnp::Error },
/// couldn't create a writer for this bot data in the storage operator
WriterError { source: opendal::Error },
/// couldn't write (modified) data for this bot to the storage operator
WriteError { source: std::io::Error },
/// couldn't finalize writing (modified) data for this bot to the storage operator
FinalizeError { source: std::io::Error },
}
impl BotDataManager {
pub async fn update<R>(
&self,
f: impl FnOnce(bot_capnp::bot::Builder<'_>) -> R,
) -> Result<R, UpdateError> {
let compressed_buffer = self
.operator
.async_reader_if_exists(PATH)
.await
.context(update_error::ReadSnafu)?;
let decompressed_reader = compressed_buffer.map(BrotliDecoder::new);
let decompressed = decompressed_reader
.map_async(|mut reader| async move {
let mut vec = Vec::new();
reader.read_to_end(&mut vec).await?;
Ok(vec)
})
.await
.transpose()
.context(update_error::DecompressionSnafu)?;
let mut message = TypedBuilder::<bot_capnp::bot::Owned>::new_default();
let ret = if let Some(mut bytes) = decompressed.as_deref() {
let message_reader = capnp::serialize::read_message_from_flat_slice_no_alloc(
&mut bytes,
Default::default(),
)
.context(update_error::DeserializeSnafu)?;
let bot_data = message_reader
.get_root()
.context(update_error::DeserializeSnafu)?;
message
.set_root(bot_data)
.context(update_error::DeserializeSnafu)?;
f(
message.get_root().unwrap(), // this is logically impossible
)
} else {
f(message.init_root())
};
let mut buffer = Vec::new();
capnp::serialize::write_message(&mut buffer, message.borrow_inner())
.context(update_error::SerializeSnafu)?;
let compressed_writer = self
.operator
.writer(PATH)
.await
.context(update_error::WriterSnafu)?
.into_futures_async_write();
let mut decompressed_writer = BrotliEncoder::new(compressed_writer);
decompressed_writer
.write_all(&buffer)
.await
.context(update_error::WriteSnafu)?;
decompressed_writer
.close()
.await
.context(update_error::FinalizeSnafu)?;
Ok(ret)
}
}

View File

@@ -1,10 +1,6 @@
use std::sync::LazyLock;
use async_compression::futures::bufread::BrotliDecoder;
use capnp::message::ReaderOptions;
use futures::AsyncReadExt;
use opendal::ErrorKind;
use futures::TryStreamExt;
use snafu::{OptionExt, Snafu};
use std::sync::LazyLock;
use twilight_model::{
application::{
command::{Command, CommandType},
@@ -17,14 +13,13 @@ use twilight_model::{
use twilight_util::builder::{
InteractionResponseDataBuilder,
command::CommandBuilder,
embed::{EmbedBuilder, EmbedFieldBuilder},
embed::{EmbedAuthorBuilder, EmbedBuilder, EmbedFieldBuilder},
};
use crate::{bot_capnp, command::State};
use crate::command::State;
const NAME: &str = "debug";
const DESCRIPTION: &str =
"(Only the bot owner can use this) Show various information for debugging purposes";
const NAME: &str = "info";
const DESCRIPTION: &str = "Show various information";
pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
CommandBuilder::new(NAME, DESCRIPTION, CommandType::ChatInput)
@@ -114,54 +109,22 @@ pub async fn handle(state: State, interaction: Interaction) {
.await
.expect("TODO");
let heat_script_description = {
let compressed_result = state
.bot_data
.reader("data.bin.brotli")
.await
.expect("TODO")
.into_futures_async_read(..)
.await;
let mut buf = Vec::default();
let mut message = capnp::message::TypedBuilder::<bot_capnp::bot::Owned>::new_default();
let fallback = message.init_root();
let message_reader;
let mut bot_data = fallback.into_reader();
match compressed_result {
Ok(compressed) => {
let mut decompressed = BrotliDecoder::new(compressed);
decompressed.read_to_end(&mut buf).await.expect("TODO");
message_reader =
capnp::serialize_packed::read_message(&*buf, ReaderOptions::default())
.expect("TODO");
bot_data = message_reader
.get_root::<bot_capnp::bot::Reader>()
.expect("TODO");
}
Err(error) if error.kind() == ErrorKind::NotFound => {
tracing::error!("TODO: proceeding with fallback");
}
Err(error) => {
tracing::error!(?error, "TODO");
return;
}
}
let heat_script_option = bot_data
.has_heat_script()
.then(|| bot_data.get_heat_script().expect("TODO"));
let heat_script_option =
heat_script_option.map(|heat_script| heat_script.to_str().expect("TODO"));
heat_script_option.map_or("none set yet".into(), |heat_script| {
format!("```\n{heat_script}\n```")
let heat_script_description = state
.bot_data_manager
.with(|bot_data| {
let heat_script_option = bot_data.has_heat_script().then(|| {
bot_data
.get_heat_script()
.expect("TODO")
.to_string()
.expect("TODO")
});
heat_script_option.map_or("none set yet".into(), |heat_script| {
format!("```\n{heat_script}\n```")
})
})
};
.await
.expect("TODO");
state
.discord_client
@@ -175,4 +138,48 @@ pub async fn handle(state: State, interaction: Interaction) {
.flags(MessageFlags::EPHEMERAL)
.await
.expect("TODO");
let mut user_id_stream = state.user_data_manager.list().await.expect("TODO");
while let Some(user_id) = user_id_stream.try_next().await.expect("TODO") {
let (consent, notification_script) = state
.user_data_manager
.with(user_id, |user_data| {
let consent = user_data.get_voice_recording_consent().unwrap();
let notification_script = user_data.has_notification_script().then_some(
user_data
.get_notification_script()
.expect("TODO")
.to_string()
.expect("TODO"),
);
(consent, notification_script)
})
.await
.expect("TODO");
let user_mention = format!("<@{user_id}>");
state
.discord_client
.interaction(state.discord_application_id)
.create_followup(&interaction.token)
.embeds(&[EmbedBuilder::new()
.author(EmbedAuthorBuilder::new(user_mention))
.field(EmbedFieldBuilder::new("Consent", format!("{consent:?}")).build())
.field(
EmbedFieldBuilder::new(
"Notification Script",
format!("{notification_script:?}"),
)
.build(),
)
.validate()
.unwrap()
.build()])
.flags(MessageFlags::EPHEMERAL)
.await
.expect("TODO");
}
}

View File

@@ -1,8 +1,12 @@
use crate::{OneToManyUniqueBTreeMap, VCs, command::State};
use crate::{
OneToManyUniqueBTreeMap, UserDataManager, VCs, command::State, option_ext::OptionExt as _,
user_capnp::user::Consent, user_data::RECORD_IF_CONSENT_UNSPECIFIED,
};
use async_trait::async_trait;
use futures::FutureExt;
use hound::{SampleFormat, WavSpec};
use opendal::Operator;
use snafu::{OptionExt, Snafu};
use snafu::{OptionExt as _, Snafu};
use songbird::{CoreEvent, Event, EventContext, EventHandler};
use std::{
io::Cursor,
@@ -104,6 +108,8 @@ struct Handler {
audio_channels: u16,
audio_sample_rate: u32,
user_data_manager: UserDataManager,
}
#[async_trait]
@@ -134,6 +140,26 @@ impl EventHandler for Handler {
tracing::info!(?user_id);
if let Some(pcm) = &voice_data.decoded_voice {
let may_record = user_id
.map_async(|user_id| {
self.user_data_manager
.with(user_id, |user_data| {
user_data.get_voice_recording_consent().unwrap()
})
.map(|result| result.expect("TODO"))
})
.await
.map_or(RECORD_IF_CONSENT_UNSPECIFIED, |consent| match consent {
Consent::Unspecified => RECORD_IF_CONSENT_UNSPECIFIED,
Consent::Granted => true,
Consent::Withheld => false,
});
if !may_record {
tracing::warn!(?user_id, "may not be recorded");
continue;
}
let elapsed = self.start_instant.elapsed();
let elapsed = elapsed.try_into().expect("TODO");
@@ -281,6 +307,8 @@ pub async fn handle(state: State, interaction: Interaction) {
audio_channels,
audio_sample_rate,
user_data_manager: state.user_data_manager,
};
{
@@ -293,9 +321,17 @@ pub async fn handle(state: State, interaction: Interaction) {
}
let channel_mention = format!("<#{voice_channel_id}>");
let bot_owner_mention = format!("<@{}>", state.discord_bot_owner_user_id);
let opt_in_mention = format!(
"</{}:{}>",
state.discord_opt_in_command_name, state.discord_opt_in_command_id
);
let opt_out_mention = format!(
"</{}:{}>",
state.discord_opt_out_command_name, state.discord_opt_out_command_id
);
state
.discord_client
.interaction(state.discord_application_id)
@@ -304,7 +340,7 @@ pub async fn handle(state: State, interaction: Interaction) {
).embeds(Some(&[
EmbedBuilder::new()
.title("Joined VC to record")
.description(format!("This bot joined {channel_mention} and intends to record. Here are some pledges backed by faith (because there is no way to verify them yourself) in {bot_owner_mention}:"))
.description(format!("This bot joined {channel_mention} and intends to record. You can opt out with {opt_out_mention} or explicitly opt in with {opt_in_mention} (I'd appreciate this one). Here are some pledges backed by faith (because there is no way to verify them yourself) in {bot_owner_mention}:"))
.field(
EmbedFieldBuilder::new("Recordings are never shared", "Audio recordings are only stored on my home server and desktop computer and will never be uploaded to services or hardware that is owned by another person: not even curated clips, and not even to people who were in the recording. When transcription to text is implemented, this will only be run on my personally owned devices and not on any internet or cloud offering.").build()
)

View File

@@ -3,38 +3,45 @@ use std::{fmt::Debug, sync::Arc};
use futures::future::BoxFuture;
use opendal::Operator;
use patricia_tree::StringPatriciaMap;
use songbird::{Songbird, driver::{Channels, SampleRate}};
use songbird::{
Songbird,
driver::{Channels, SampleRate},
};
use tokio_util::sync::CancellationToken;
use twilight_model::{
application::{command::Command, interaction::Interaction},
id::{
Id,
marker::{ApplicationMarker, UserMarker},
marker::{ApplicationMarker, CommandMarker, UserMarker},
},
};
use crate::{VCs, track_vcs::GuildVoiceChannelToTextChannel};
use crate::{BotDataManager, GuildVoiceChannelToTextChannel, UserDataManager, VCs};
mod debug;
mod join;
mod leave;
mod opt_in;
mod opt_out;
pub mod info;
pub mod join;
pub mod leave;
pub mod opt_in;
pub mod opt_out;
#[derive(Debug, Clone)]
pub struct State {
pub audio_channels: Channels,
pub audio_sample_rate: SampleRate,
pub bot_data: Operator,
pub bot_data_manager: BotDataManager,
pub cancellation_token: CancellationToken,
pub discord_application_id: Id<ApplicationMarker>,
pub discord_bot_owner_user_id: Id<UserMarker>,
pub discord_client: Arc<twilight_http::Client>,
pub discord_opt_in_command_id: Id<CommandMarker>,
pub discord_opt_in_command_name: Arc<str>,
pub discord_opt_out_command_id: Id<CommandMarker>,
pub discord_opt_out_command_name: Arc<str>,
pub discord_user_id: Id<UserMarker>,
pub discord_voice_channel_corresponding_text_channel: Arc<GuildVoiceChannelToTextChannel>,
pub recording_data: Operator,
pub songbird: Arc<Songbird>,
pub user_data: Operator,
pub user_data_manager: UserDataManager,
pub vcs: Arc<VCs>,
}
@@ -51,7 +58,7 @@ where
pub fn all() -> Vec<(&'static Command, BoxedHandler)> {
vec![
(&debug::COMMAND, box_handler(debug::handle)),
(&info::COMMAND, box_handler(info::handle)),
(&join::COMMAND, box_handler(join::handle)),
(&leave::COMMAND, box_handler(leave::handle)),
(&opt_in::COMMAND, box_handler(opt_in::handle)),

View File

@@ -1,12 +1,16 @@
use std::sync::LazyLock;
use twilight_model::application::{
command::{Command, CommandType},
interaction::Interaction,
use twilight_model::{
application::{
command::{Command, CommandType},
interaction::Interaction,
},
channel::message::MessageFlags,
http::interaction::{InteractionResponse, InteractionResponseType},
};
use twilight_util::builder::command::CommandBuilder;
use twilight_util::builder::{InteractionResponseDataBuilder, command::CommandBuilder};
use crate::command::State;
use crate::{command::State, user_capnp::user::Consent};
const NAME: &str = "opt-in";
const DESCRIPTION: &str = "Opt in to being recorded";
@@ -20,5 +24,67 @@ pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
#[tracing::instrument]
pub async fn handle(state: State, interaction: Interaction) {
todo!();
let user_id = interaction
.member
.as_ref()
.and_then(|member| member.user.as_ref().map(|user| user.id));
let user_id = match user_id {
Some(user_id) => user_id,
None => {
state
.discord_client
.interaction(state.discord_application_id)
.create_response(
interaction.id,
&interaction.token,
&InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(
InteractionResponseDataBuilder::new()
.content("TODO")
.build(),
),
},
)
.await
.expect("TODO");
return;
}
};
let previous_consent = state
.user_data_manager
.update(user_id, |mut user_data| {
let previous_consent = user_data
.reborrow()
.get_voice_recording_consent()
.expect("TODO");
user_data.set_voice_recording_consent(Consent::Granted);
previous_consent
})
.await
.expect("TODO");
state
.discord_client
.interaction(state.discord_application_id)
.create_response(
interaction.id,
&interaction.token,
&InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(
InteractionResponseDataBuilder::new()
.content(format!(
"opted you in, your previous consent was {previous_consent:?}"
))
.flags(MessageFlags::EPHEMERAL)
.build(),
),
},
)
.await
.expect("TODO");
}

View File

@@ -1,12 +1,16 @@
use std::sync::LazyLock;
use twilight_model::application::{
command::{Command, CommandType},
interaction::Interaction,
use twilight_model::{
application::{
command::{Command, CommandType},
interaction::Interaction,
},
channel::message::MessageFlags,
http::interaction::{InteractionResponse, InteractionResponseType},
};
use twilight_util::builder::command::CommandBuilder;
use twilight_util::builder::{InteractionResponseDataBuilder, command::CommandBuilder};
use crate::command::State;
use crate::{command::State, user_capnp::user::Consent};
const NAME: &str = "opt-out";
const DESCRIPTION: &str = "Opt out of being recorded";
@@ -20,5 +24,67 @@ pub static COMMAND: LazyLock<Command> = LazyLock::new(|| {
#[tracing::instrument]
pub async fn handle(state: State, interaction: Interaction) {
todo!();
let user_id = interaction
.member
.as_ref()
.and_then(|member| member.user.as_ref().map(|user| user.id));
let user_id = match user_id {
Some(user_id) => user_id,
None => {
state
.discord_client
.interaction(state.discord_application_id)
.create_response(
interaction.id,
&interaction.token,
&InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(
InteractionResponseDataBuilder::new()
.content("TODO")
.build(),
),
},
)
.await
.expect("TODO");
return;
}
};
let previous_consent = state
.user_data_manager
.update(user_id, |mut user_data| {
let previous_consent = user_data
.reborrow()
.get_voice_recording_consent()
.expect("TODO");
user_data.set_voice_recording_consent(Consent::Withheld);
previous_consent
})
.await
.expect("TODO");
state
.discord_client
.interaction(state.discord_application_id)
.create_response(
interaction.id,
&interaction.token,
&InteractionResponse {
kind: InteractionResponseType::ChannelMessageWithSource,
data: Some(
InteractionResponseDataBuilder::new()
.content(format!(
"opted you out, your previous consent was {previous_consent:?}"
))
.flags(MessageFlags::EPHEMERAL)
.build(),
),
},
)
.await
.expect("TODO");
}

View File

@@ -1,18 +1,24 @@
mod command;
mod bot_data;
pub mod command;
mod one_to_many;
mod one_to_many_with_data;
mod one_to_one;
mod operator_ext;
mod option_ext;
mod storage;
mod track_vcs;
mod user_data;
mod vc_user;
capnp::generated_code!(mod bot_capnp);
capnp::generated_code!(mod user_capnp);
pub use bot_data::BotDataManager;
pub use command::{Router as CommandRouter, State, all as all_commands};
pub use one_to_many::OneToManyUniqueBTreeMap;
pub use one_to_many_with_data::OneToManyUniqueBTreeMapWithData;
pub use one_to_one::OneToOneBTreeMap;
pub use operator_ext::OperatorExt;
pub use storage::Storage;
pub use track_vcs::{GuildVoiceChannelToTextChannel, VCs, initialize_vcs, update_vcs};
pub use user_data::UserDataManager;
pub use vc_user::{UserInVCData, VoiceStatus};
capnp::generated_code!(pub mod user_capnp);
capnp::generated_code!(pub mod bot_capnp);

View File

@@ -1,7 +1,7 @@
use clap::Parser;
use fomo_reducer::{
CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, all_commands, initialize_vcs,
update_vcs,
BotDataManager, CommandRouter, GuildVoiceChannelToTextChannel, State, Storage, UserDataManager,
all_commands, command, initialize_vcs, update_vcs,
};
use secrecy::{ExposeSecret, SecretString};
use snafu::{OptionExt, ResultExt, Snafu};
@@ -10,7 +10,7 @@ use songbird::{
driver::{Channels, DecodeConfig, SampleRate},
shards::TwilightMap,
};
use std::{fmt::Debug, str::FromStr, sync::Arc};
use std::{collections::BTreeMap, fmt::Debug, str::FromStr, sync::Arc};
use strum::EnumString;
use tokio::{select, signal::ctrl_c, task::JoinSet};
use tokio_util::{sync::CancellationToken, time::FutureExt as _};
@@ -275,7 +275,7 @@ async fn main() -> Result<(), MainError> {
let commands = all_commands();
let _returned_commands = interaction_client
let returned_commands = interaction_client
.set_global_commands(
Vec::from_iter(
commands
@@ -290,6 +290,25 @@ async fn main() -> Result<(), MainError> {
.await
.expect("failed to deserialize set commands"); // TODO
let mut discord_command_name_to_returned_command = BTreeMap::from_iter(
returned_commands
.into_iter()
.map(|command| (command.name.clone(), command)),
);
let discord_opt_in_command = discord_command_name_to_returned_command
.remove(&command::opt_in::COMMAND.name)
.expect("TODO");
let discord_opt_out_command = discord_command_name_to_returned_command
.remove(&command::opt_out::COMMAND.name)
.expect("TODO");
let discord_opt_in_command_id = discord_opt_in_command.id.expect("TODO");
let discord_opt_out_command_id = discord_opt_out_command.id.expect("TODO");
let discord_opt_in_command_name = discord_opt_in_command.name.into();
let discord_opt_out_command_name = discord_opt_out_command.name.into();
let vcs = initialize_vcs(&discord_client).await;
let command_router = CommandRouter::from_iter(commands);
@@ -303,6 +322,9 @@ async fn main() -> Result<(), MainError> {
let recording_data = recording_data.into_inner();
let user_data = user_data.into_inner();
let bot_data_manager = BotDataManager::new(bot_data);
let user_data_manager = UserDataManager::new(user_data);
let discord_voice_channel_corresponding_text_channel = {
let mut map = GuildVoiceChannelToTextChannel::default();
@@ -322,16 +344,20 @@ async fn main() -> Result<(), MainError> {
let state = State {
audio_channels,
audio_sample_rate,
bot_data,
bot_data_manager,
cancellation_token: cancellation_token.clone(),
discord_application_id,
discord_bot_owner_user_id,
discord_client,
discord_opt_in_command_id,
discord_opt_in_command_name,
discord_opt_out_command_id,
discord_opt_out_command_name,
discord_user_id,
discord_voice_channel_corresponding_text_channel,
recording_data,
songbird,
user_data,
user_data_manager,
vcs,
};

25
src/operator_ext.rs Normal file
View File

@@ -0,0 +1,25 @@
use extension_traits::extension;
use opendal::{Buffer, Error, ErrorKind, FuturesAsyncReader, Operator};
#[extension(pub trait OperatorExt)]
impl Operator {
async fn read_if_exists(&self, path: &str) -> Result<Option<Buffer>, Error> {
match self.read(path).await {
Ok(buffer) => Ok(Some(buffer)),
Err(error) if matches!(error.kind(), ErrorKind::NotFound) => Ok(None),
Err(error) => Err(error),
}
}
async fn async_reader_if_exists(
&self,
path: &str,
) -> Result<Option<FuturesAsyncReader>, Error> {
let reader = self.reader(path).await?;
match reader.into_futures_async_read(..).await {
Ok(reader) => Ok(Some(reader)),
Err(error) if matches!(error.kind(), ErrorKind::NotFound) => Ok(None),
Err(error) => Err(error),
}
}
}

11
src/option_ext.rs Normal file
View File

@@ -0,0 +1,11 @@
use extension_traits::extension;
#[extension(pub trait OptionExt)]
impl<S> Option<S> {
async fn map_async<M, Fut: Future<Output = M>, F: FnOnce(S) -> Fut>(self, f: F) -> Option<M> {
match self {
Some(s) => Some(f(s).await),
None => None,
}
}
}

View File

@@ -2,7 +2,6 @@ use std::{fmt::Debug, str::FromStr};
use opendal::{IntoOperatorUri, Operator, OperatorUri};
#[derive(Clone)]
pub struct Storage {
uri: OperatorUri,

View File

@@ -12,7 +12,8 @@ use twilight_model::{
use crate::{OneToManyUniqueBTreeMapWithData, OneToOneBTreeMap, UserInVCData, VoiceStatus};
pub type GuildVoiceChannelToTextChannel = BTreeMap<Id<GuildMarker>, OneToOneBTreeMap<Id<ChannelMarker>, Id<ChannelMarker>>>;
pub type GuildVoiceChannelToTextChannel =
BTreeMap<Id<GuildMarker>, OneToOneBTreeMap<Id<ChannelMarker>, Id<ChannelMarker>>>;
type VCsInGuild = OneToManyUniqueBTreeMapWithData<Id<ChannelMarker>, Id<UserMarker>, UserInVCData>;
pub type VCs = DashMap<Id<GuildMarker>, VCsInGuild>;

254
src/user_data.rs Normal file
View File

@@ -0,0 +1,254 @@
use std::str::FromStr;
use async_compression::futures::{bufread::BrotliDecoder, write::BrotliEncoder};
use capnp::message::TypedBuilder;
use futures::{AsyncReadExt, AsyncWriteExt, TryStream, TryStreamExt};
use opendal::Operator;
use snafu::{OptionExt as _, ResultExt as _, Snafu, ensure};
use twilight_model::id::{Id, marker::UserMarker};
use crate::{OperatorExt, option_ext::OptionExt as _, user_capnp};
pub const RECORD_IF_CONSENT_UNSPECIFIED: bool = true;
#[derive(Debug, Clone)]
pub struct UserDataManager {
operator: Operator,
}
impl UserDataManager {
pub fn new(operator: Operator) -> Self {
Self { operator }
}
}
fn path(id: Id<UserMarker>) -> String {
format!("{id}/data.bin.brotli")
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum ParsePathError {
/// paths must have a / in them because that's how user data is stored, but this one doesn't have one
MissingSlashError,
/// if this isn't a directory, then the file must be "data.bin.brotli" but it was actually {actual:?}
WrongFileError { actual: String },
/// couldn't parse the directory as a user ID
ParseUserIdError {
source: <Id<UserMarker> as FromStr>::Err,
},
}
fn parse(path: &str) -> Result<Id<UserMarker>, ParsePathError> {
let (directory, file) = path
.rsplit_once("/")
.context(parse_path_error::MissingSlashSnafu)?;
ensure!(
file == "" || file == "data.bin.brotli",
parse_path_error::WrongFileSnafu {
actual: file.to_owned()
}
);
let user_id = directory
.parse()
.context(parse_path_error::ParseUserIdSnafu)?;
Ok(user_id)
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum ListError {
/// error creating a lister through the storage operator
CreateListerError { source: opendal::Error },
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum EntryError {
/// failed to get an entry from the storage operator's lister
ReceiveEntryError { source: opendal::Error },
/// failed to parse the entry as an acceptable path
ParsePathError { source: ParsePathError },
}
impl UserDataManager {
pub async fn list(
&self,
) -> Result<impl TryStream<Ok = Id<UserMarker>, Error = EntryError> + Unpin, ListError> {
let lister = self
.operator
.lister("")
.await
.context(list_error::CreateListerSnafu)?;
Ok(lister
.map_err(|error| EntryError::ReceiveEntryError { source: error })
.and_then(|entry| {
std::future::ready(parse(entry.path()).context(entry_error::ParsePathSnafu))
}))
}
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum WithError {
/// couldn't read data for this user from the storage operator
ReadError { source: opendal::Error },
/// couldn't decompress the user data from storage
DecompressionError { source: std::io::Error },
/// couldn't deserialize the user data
DeserializeError { source: capnp::Error },
}
impl UserDataManager {
pub async fn with<R>(
&self,
id: Id<UserMarker>,
f: impl FnOnce(user_capnp::user::Reader<'_>) -> R,
) -> Result<R, WithError> {
let compressed_buffer = self
.operator
.async_reader_if_exists(&path(id))
.await
.context(with_error::ReadSnafu)?;
let decompressed_reader = compressed_buffer.map(BrotliDecoder::new);
let decompressed = decompressed_reader
.map_async(|mut reader| async move {
let mut vec = Vec::new();
reader.read_to_end(&mut vec).await?;
Ok(vec)
})
.await
.transpose()
.context(with_error::DecompressionSnafu)?;
let mut message = TypedBuilder::<user_capnp::user::Owned>::new_default();
let fallback = message.init_root();
let mut user_data = fallback.into_reader();
let message_reader;
if let Some(mut bytes) = decompressed.as_deref() {
message_reader = capnp::serialize::read_message_from_flat_slice_no_alloc(
&mut bytes,
Default::default(),
)
.context(with_error::DeserializeSnafu)?;
user_data = message_reader
.get_root()
.context(with_error::DeserializeSnafu)?;
}
Ok(f(user_data))
}
}
#[derive(Debug, Snafu)]
#[snafu(module)]
pub enum UpdateError {
/// couldn't read data for this user from the storage operator
ReadError { source: opendal::Error },
/// couldn't decompress the user data from storage
DecompressionError { source: std::io::Error },
/// couldn't deserialize the user data
DeserializeError { source: capnp::Error },
/// couldn't serialize the (modified) user data
SerializeError { source: capnp::Error },
/// couldn't create a writer for this user data in the storage operator
WriterError { source: opendal::Error },
/// couldn't write (modified) data for this user to the storage operator
WriteError { source: std::io::Error },
/// couldn't finalize writing (modified) data for this user to the storage operator
FinalizeError { source: std::io::Error },
}
impl UserDataManager {
pub async fn update<R>(
&self,
id: Id<UserMarker>,
f: impl FnOnce(user_capnp::user::Builder<'_>) -> R,
) -> Result<R, UpdateError> {
let path = path(id);
let compressed_buffer = self
.operator
.async_reader_if_exists(&path)
.await
.context(update_error::ReadSnafu)?;
let decompressed_reader = compressed_buffer.map(BrotliDecoder::new);
let decompressed = decompressed_reader
.map_async(|mut reader| async move {
let mut vec = Vec::new();
reader.read_to_end(&mut vec).await?;
Ok(vec)
})
.await
.transpose()
.context(update_error::DecompressionSnafu)?;
let mut message = TypedBuilder::<user_capnp::user::Owned>::new_default();
let ret = if let Some(mut bytes) = decompressed.as_deref() {
let message_reader = capnp::serialize::read_message_from_flat_slice_no_alloc(
&mut bytes,
Default::default(),
)
.context(update_error::DeserializeSnafu)?;
let user_data = message_reader
.get_root()
.context(update_error::DeserializeSnafu)?;
message
.set_root(user_data)
.context(update_error::DeserializeSnafu)?;
f(
message.get_root().unwrap(), // this is logically impossible
)
} else {
f(message.init_root())
};
let mut buffer = Vec::new();
capnp::serialize::write_message(&mut buffer, message.borrow_inner())
.context(update_error::SerializeSnafu)?;
let compressed_writer = self
.operator
.writer(&path)
.await
.context(update_error::WriterSnafu)?
.into_futures_async_write();
let mut decompressed_writer = BrotliEncoder::new(compressed_writer);
decompressed_writer
.write_all(&buffer)
.await
.context(update_error::WriteSnafu)?;
decompressed_writer
.close()
.await
.context(update_error::FinalizeSnafu)?;
Ok(ret)
}
}

View File

@@ -3,5 +3,11 @@
struct User {
notificationScript @0 :Text;
voiceRecordingConsent @1 :Bool;
voiceRecordingConsent @1 :Consent = unspecified;
enum Consent {
unspecified @0;
granted @1;
withheld @2;
}
}