Compare commits
3 Commits
meta
...
maybe-skia
| Author | SHA1 | Date | |
|---|---|---|---|
| d8e94cf574 | |||
| 6038240d5a | |||
| 4d71f7fe23 |
@ -1,10 +1,3 @@
|
|||||||
DISCORD_TOKEN=
|
DISCORD_TOKEN=
|
||||||
LASTFM_API_KEY=
|
LASTFM_API_KEY=
|
||||||
DATABASE_URL=sqlite:watcat.db
|
DATABASE_URL=sqlite:watcat.db
|
||||||
|
|
||||||
# optional, for spotify support
|
|
||||||
RSPOTIFY_CLIENT_ID=
|
|
||||||
RSPOTIFY_CLIENT_SECRET=
|
|
||||||
|
|
||||||
# optional, to set color cache size. set to 0 to disable
|
|
||||||
MAX_CACHE_SIZE=
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@
|
|||||||
/.env
|
/.env
|
||||||
/watcat.db*
|
/watcat.db*
|
||||||
/http-cacache
|
/http-cacache
|
||||||
/overrides.txt
|
|
||||||
|
|||||||
293
Cargo.lock
generated
293
Cargo.lock
generated
@ -172,6 +172,17 @@ version = "1.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "auto-palette"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "65e79afc54a4a4629411811a644e778c7d8f6889b8ecf4c1d4a13f3f33db408d"
|
||||||
|
dependencies = [
|
||||||
|
"image",
|
||||||
|
"num-traits",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
@ -243,29 +254,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bindgen"
|
|
||||||
version = "0.69.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.9.1",
|
|
||||||
"cexpr",
|
|
||||||
"clang-sys",
|
|
||||||
"itertools",
|
|
||||||
"lazy_static",
|
|
||||||
"lazycell",
|
|
||||||
"log",
|
|
||||||
"prettyplease",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"regex",
|
|
||||||
"rustc-hash",
|
|
||||||
"shlex",
|
|
||||||
"syn 2.0.101",
|
|
||||||
"which",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
@ -410,24 +398,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.22"
|
version = "1.2.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "32db95edf998450acc7881c932f94cd9b05c87b4b2599e8bab064753da4acfd1"
|
checksum = "5f4ac86a9e5bc1e2b3449ab9d7d3a6a405e3d1bb28d7b9be8614f55846ae3766"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"jobserver",
|
"jobserver",
|
||||||
"libc",
|
"libc",
|
||||||
"shlex",
|
"shlex",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cexpr"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
||||||
dependencies = [
|
|
||||||
"nom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-expr"
|
name = "cfg-expr"
|
||||||
version = "0.15.8"
|
version = "0.15.8"
|
||||||
@ -459,17 +438,6 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clang-sys"
|
|
||||||
version = "1.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
"libc",
|
|
||||||
"libloading",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "color_quant"
|
name = "color_quant"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -713,18 +681,6 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "enum_dispatch"
|
|
||||||
version = "0.3.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd"
|
|
||||||
dependencies = [
|
|
||||||
"once_cell",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.101",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
@ -991,10 +947,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"js-sys",
|
|
||||||
"libc",
|
"libc",
|
||||||
"wasi 0.11.0+wasi-snapshot-preview1",
|
"wasi 0.11.0+wasi-snapshot-preview1",
|
||||||
"wasm-bindgen",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1100,12 +1054,6 @@ dependencies = [
|
|||||||
"foldhash",
|
"foldhash",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.16.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashlink"
|
name = "hashlink"
|
||||||
version = "0.10.0"
|
version = "0.10.0"
|
||||||
@ -1576,12 +1524,12 @@ checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.12.0"
|
version = "2.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f"
|
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.16.0",
|
"hashbrown 0.15.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1673,12 +1621,6 @@ dependencies = [
|
|||||||
"spin",
|
"spin",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lazycell"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lebe"
|
name = "lebe"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@ -1707,16 +1649,6 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libloading"
|
|
||||||
version = "0.8.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"windows-targets 0.53.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libm"
|
name = "libm"
|
||||||
version = "0.2.15"
|
version = "0.2.15"
|
||||||
@ -1734,12 +1666,6 @@ dependencies = [
|
|||||||
"vcpkg",
|
"vcpkg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "linux-raw-sys"
|
|
||||||
version = "0.4.15"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.9.4"
|
version = "0.9.4"
|
||||||
@ -1777,26 +1703,6 @@ dependencies = [
|
|||||||
"imgref",
|
"imgref",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "magick_rust"
|
|
||||||
version = "1.0.0"
|
|
||||||
dependencies = [
|
|
||||||
"bindgen",
|
|
||||||
"libc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "maybe-async"
|
|
||||||
version = "0.2.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5cf92c10c7e361d6b99666ec1c6f9805b0bea2c3bd8c78dc6fe98ac5bd78db11"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.101",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "maybe-rayon"
|
name = "maybe-rayon"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -2297,16 +2203,6 @@ dependencies = [
|
|||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "prettyplease"
|
|
||||||
version = "0.2.32"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "664ec5419c51e34154eec046ebcba56312d5a2fc3b09a06da188e1ad21afadf6"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"syn 2.0.101",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.95"
|
version = "1.0.95"
|
||||||
@ -2493,7 +2389,7 @@ checksum = "78c81d000a2c524133cc00d2f92f019d399e57906c3b7119271a2495354fe895"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"rustix 1.0.7",
|
"rustix",
|
||||||
"windows",
|
"windows",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2605,7 +2501,6 @@ dependencies = [
|
|||||||
"system-configuration 0.6.1",
|
"system-configuration 0.6.1",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-native-tls",
|
"tokio-native-tls",
|
||||||
"tokio-socks",
|
|
||||||
"tower",
|
"tower",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
@ -2670,89 +2565,12 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rspotify"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77beedc33ecff4c39e8ef0e6f7ebc8d849f3ffebbeb786f9997d96f0d9cf4017"
|
|
||||||
dependencies = [
|
|
||||||
"async-stream",
|
|
||||||
"async-trait",
|
|
||||||
"base64 0.22.1",
|
|
||||||
"chrono",
|
|
||||||
"futures",
|
|
||||||
"getrandom 0.2.16",
|
|
||||||
"log",
|
|
||||||
"maybe-async",
|
|
||||||
"rspotify-http",
|
|
||||||
"rspotify-macros",
|
|
||||||
"rspotify-model",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sha2",
|
|
||||||
"thiserror 2.0.12",
|
|
||||||
"url",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rspotify-http"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fde1ea9e2a49698cffbc994a83f5f909b37736c31cccb202f9577e8a32df3a63"
|
|
||||||
dependencies = [
|
|
||||||
"async-trait",
|
|
||||||
"log",
|
|
||||||
"maybe-async",
|
|
||||||
"reqwest 0.12.15",
|
|
||||||
"serde_json",
|
|
||||||
"thiserror 2.0.12",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rspotify-macros"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ee3dfb51ee54bd754ad76e96ad60a3b64bc70ae33a89261d9dbabc4c148a496f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rspotify-model"
|
|
||||||
version = "0.15.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "018f29a6a8c47cfe7923c48140ed546a395f660c7af05b73e6001d4505f89c8d"
|
|
||||||
dependencies = [
|
|
||||||
"chrono",
|
|
||||||
"enum_dispatch",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"strum",
|
|
||||||
"thiserror 2.0.12",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.24"
|
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 = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-hash"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustix"
|
|
||||||
version = "0.38.44"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 2.9.1",
|
|
||||||
"errno",
|
|
||||||
"libc",
|
|
||||||
"linux-raw-sys 0.4.15",
|
|
||||||
"windows-sys 0.59.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustix"
|
name = "rustix"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
@ -2762,7 +2580,7 @@ dependencies = [
|
|||||||
"bitflags 2.9.1",
|
"bitflags 2.9.1",
|
||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.9.4",
|
"linux-raw-sys",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2964,19 +2782,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.219"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||||
dependencies = [
|
|
||||||
"serde_core",
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_core"
|
|
||||||
version = "1.0.228"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@ -2992,9 +2800,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.228"
|
version = "1.0.219"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
|
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -3447,27 +3255,6 @@ dependencies = [
|
|||||||
"unicode-properties",
|
"unicode-properties",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum"
|
|
||||||
version = "0.27.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf"
|
|
||||||
dependencies = [
|
|
||||||
"strum_macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strum_macros"
|
|
||||||
version = "0.27.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7"
|
|
||||||
dependencies = [
|
|
||||||
"heck",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.101",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "subtle"
|
name = "subtle"
|
||||||
version = "2.6.1"
|
version = "2.6.1"
|
||||||
@ -3598,7 +3385,7 @@ dependencies = [
|
|||||||
"fastrand",
|
"fastrand",
|
||||||
"getrandom 0.3.3",
|
"getrandom 0.3.3",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"rustix 1.0.7",
|
"rustix",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3805,18 +3592,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tokio-socks"
|
|
||||||
version = "0.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"futures-util",
|
|
||||||
"thiserror 1.0.69",
|
|
||||||
"tokio",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-stream"
|
name = "tokio-stream"
|
||||||
version = "0.1.17"
|
version = "0.1.17"
|
||||||
@ -4286,21 +4061,21 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "watcat"
|
name = "watcat"
|
||||||
version = "0.6.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arabic_reshaper",
|
"arabic_reshaper",
|
||||||
|
"auto-palette",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
"http-cache-reqwest",
|
"http-cache-reqwest",
|
||||||
"image",
|
"image",
|
||||||
"imagetext",
|
"imagetext",
|
||||||
"lastfm",
|
"lastfm",
|
||||||
"magick_rust",
|
|
||||||
"palette",
|
"palette",
|
||||||
"reqwest 0.12.15",
|
"reqwest 0.12.15",
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
"rspotify",
|
|
||||||
"serenity",
|
"serenity",
|
||||||
"sqlx",
|
"sqlx",
|
||||||
|
"tiny-skia",
|
||||||
"tokio",
|
"tokio",
|
||||||
"unicode-bidi",
|
"unicode-bidi",
|
||||||
]
|
]
|
||||||
@ -4345,18 +4120,6 @@ 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 = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "which"
|
|
||||||
version = "4.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"home",
|
|
||||||
"once_cell",
|
|
||||||
"rustix 0.38.44",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "whoami"
|
name = "whoami"
|
||||||
version = "1.6.0"
|
version = "1.6.0"
|
||||||
@ -4711,9 +4474,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winnow"
|
name = "winnow"
|
||||||
version = "0.7.13"
|
version = "0.7.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf"
|
checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|||||||
11
Cargo.toml
11
Cargo.toml
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "watcat"
|
name = "watcat"
|
||||||
version = "0.6.2"
|
version = "0.2.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -11,15 +11,18 @@ reqwest = "0.12"
|
|||||||
reqwest-middleware = "0.4.2"
|
reqwest-middleware = "0.4.2"
|
||||||
http-cache-reqwest = "0.15.1"
|
http-cache-reqwest = "0.15.1"
|
||||||
palette = "0.7.6"
|
palette = "0.7.6"
|
||||||
rspotify = "0.15.0"
|
tiny-skia = "0.11.4"
|
||||||
|
auto-palette = "0.8.2"
|
||||||
|
#rand = "0.9.1"
|
||||||
|
#rayon = "1.10.0"
|
||||||
# text rendering dependencies
|
# text rendering dependencies
|
||||||
arabic_reshaper = "0.4.2"
|
arabic_reshaper = "0.4.2"
|
||||||
unicode-bidi = "0.3.18"
|
unicode-bidi = "0.3.18"
|
||||||
image = "0.25.6"
|
image = "0.25.6"
|
||||||
imagetext = { git = "https://github.com/nathanielfernandes/imagetext" }
|
imagetext = { git = "https://github.com/nathanielfernandes/imagetext" }
|
||||||
|
|
||||||
[dependencies.magick_rust]
|
#[dependencies.magick_rust]
|
||||||
path = "./magick-rust"
|
#path = "./magick-rust"
|
||||||
|
|
||||||
[dependencies.tokio]
|
[dependencies.tokio]
|
||||||
version = "1.21.2"
|
version = "1.21.2"
|
||||||
|
|||||||
11
README.md
11
README.md
@ -28,14 +28,7 @@ init the database ``sqlx migrate run``
|
|||||||
TODO
|
TODO
|
||||||
----
|
----
|
||||||
|
|
||||||
+ ~~add art and lastfm url fetching~~
|
+ ~~literally just add the text~~
|
||||||
+ ~~add help command~~
|
+ add easter egg
|
||||||
+ ~~refactor to combine repeated parts of art, url, and fmi.~~
|
|
||||||
+ ~~use macro for commands~~
|
|
||||||
+ ~~use Option instead of empty string sentinel value~~
|
|
||||||
+ ~~add cache for album art colors~~
|
|
||||||
+ ~~add spotify link fetching~~
|
|
||||||
+ ~~add arbitrary spotify searching~~
|
|
||||||
+ ~~use static seed for kmeans~~
|
|
||||||
+ make various parameters user-configurable
|
+ make various parameters user-configurable
|
||||||
+ use tiny-skia instead of magick-rust?
|
+ use tiny-skia instead of magick-rust?
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 4.4 KiB |
93
src/img.rs
Normal file
93
src/img.rs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
use image::{RgbaImage, ExtendedColorType, ImageEncoder, load_from_memory};
|
||||||
|
use image::codecs::png::PngEncoder;
|
||||||
|
use tiny_skia::{Pixmap, Transform, PixmapPaint, BlendMode, FilterQuality, Color, Paint, Shader};
|
||||||
|
use palette::{Srgb, Lab, FromColor};
|
||||||
|
use auto_palette::{ImageData, Palette};
|
||||||
|
/*use palette::color_difference::{EuclideanDistance, ImprovedDeltaE};
|
||||||
|
use palette::white_point::D65;
|
||||||
|
use rand::{SeedableRng};
|
||||||
|
use rand::prelude::{IteratorRandom};
|
||||||
|
use rand::rngs::{SmallRng};
|
||||||
|
use std::ops::{Add, Div};//{Add, Sub, Mul};*/
|
||||||
|
|
||||||
|
pub fn save_to_memory_png(p: &RgbaImage) -> Result<Vec<u8>, String> {
|
||||||
|
let (width, height) = p.dimensions();
|
||||||
|
let mut blob = Vec::<u8>::new();
|
||||||
|
let png_encoder = PngEncoder::new(&mut blob);
|
||||||
|
match png_encoder.write_image(p, width, height, ExtendedColorType::Rgba8) {
|
||||||
|
Ok(()) => Ok(blob),
|
||||||
|
Err(_) => Err("Failed to encode text png".to_string()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ensure_32_bit_png(p: &[u8]) -> Result<Vec<u8>, String> {
|
||||||
|
let img = match load_from_memory(p) {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(e) => return Err(format!("Failed to load png: {e}")),
|
||||||
|
};
|
||||||
|
save_to_memory_png(&img.into_rgba8())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn scale_skia_pixmap(p: Pixmap, width: u32, height: u32) -> Option<Pixmap> {
|
||||||
|
let mut new_pixmap = Pixmap::new(width, height)?;
|
||||||
|
let width_scale = width as f32 / p.width() as f32;
|
||||||
|
let height_scale = height as f32 / p.width() as f32;
|
||||||
|
let matrix = Transform::from_scale(width_scale, height_scale);
|
||||||
|
let pixmap_paint = PixmapPaint {
|
||||||
|
opacity: 1.0,
|
||||||
|
blend_mode: BlendMode::Source,
|
||||||
|
quality: FilterQuality::Bilinear,
|
||||||
|
};
|
||||||
|
new_pixmap.draw_pixmap(0, 0, p.as_ref(), &pixmap_paint, matrix, None);
|
||||||
|
Some(new_pixmap)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lab_to_skia_color(c: Lab) -> Result<Color, String> {
|
||||||
|
let rgb: Srgb<f32> = Srgb::from_color(c).into_format();
|
||||||
|
match Color::from_rgba(rgb.red, rgb.green, rgb.blue, 1.0) {
|
||||||
|
Some(c) => Ok(c),
|
||||||
|
None => Err(format!("Invalid color: {rgb:?}")),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn color_paint_from_lab_color<'a>(c: Lab) -> Result<Paint<'a>, String> {
|
||||||
|
//let color = lab_to_skia_color(c)?;
|
||||||
|
Ok(Paint {
|
||||||
|
shader: Shader::SolidColor(lab_to_skia_color(c)?),
|
||||||
|
anti_alias: true,
|
||||||
|
blend_mode: BlendMode::Source,
|
||||||
|
force_hq_pipeline: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dominant_colors_as_paints<'a>(p: &Pixmap) -> Result<(Paint<'a>, Paint<'a>), String> {
|
||||||
|
let imagedata = match ImageData::new(p.width(), p.height(), p.data()) {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(_) => return Err("Failed to load imagedata".to_string()),
|
||||||
|
};
|
||||||
|
let pal: Palette<f32> = match Palette::extract(&imagedata) {
|
||||||
|
Ok(p) => p,
|
||||||
|
Err(_) => return Err("Failed to to create palette".to_string()),
|
||||||
|
};
|
||||||
|
let colors: Vec<_> = match pal.find_swatches(2) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return Err("Failed to get swatches".to_string()),
|
||||||
|
};
|
||||||
|
let colors = colors.iter().map(|swatch| {
|
||||||
|
let rgb = swatch.color().to_rgb();
|
||||||
|
Srgb::new(rgb.r, rgb.g, rgb.b).into()
|
||||||
|
}).collect::<Vec<Srgb<f32>>>();
|
||||||
|
Ok((Paint {
|
||||||
|
shader: Shader::SolidColor(Color::from_rgba(colors[0].red, colors[0].green, colors[0].blue, 1.0).unwrap()),
|
||||||
|
anti_alias: true,
|
||||||
|
blend_mode: BlendMode::Source,
|
||||||
|
force_hq_pipeline: false,
|
||||||
|
},
|
||||||
|
Paint {
|
||||||
|
shader: Shader::SolidColor(Color::from_rgba(colors[1].red, colors[1].green, colors[1].blue, 1.0).unwrap()),
|
||||||
|
anti_alias: true,
|
||||||
|
blend_mode: BlendMode::Source,
|
||||||
|
force_hq_pipeline: false,
|
||||||
|
}))
|
||||||
|
}
|
||||||
545
src/main.rs
545
src/main.rs
@ -1,8 +1,12 @@
|
|||||||
|
//#![allow(dead_code)]
|
||||||
|
//#![allow(unused_variables)]
|
||||||
|
//#![allow(unused_imports)]
|
||||||
|
//#![allow(unused_macros)]
|
||||||
extern crate dotenvy;
|
extern crate dotenvy;
|
||||||
extern crate lastfm;
|
extern crate lastfm;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
extern crate reqwest_middleware;
|
extern crate reqwest_middleware;
|
||||||
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, HttpCacheOptions,};
|
use http_cache_reqwest::{CACacheManager, Cache, CacheMode, HttpCache, HttpCacheOptions};
|
||||||
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::builder::{CreateAttachment, CreateMessage};
|
use serenity::builder::{CreateAttachment, CreateMessage};
|
||||||
@ -10,34 +14,27 @@ use serenity::model::channel::Message;
|
|||||||
use serenity::model::id::UserId;
|
use serenity::model::id::UserId;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
|
||||||
extern crate magick_rust;
|
extern crate tiny_skia;
|
||||||
use magick_rust::{
|
extern crate image;
|
||||||
ColorspaceType, CompositeOperator, FilterType, MagickWand, PixelWand, magick_wand_genesis,
|
|
||||||
};
|
//extern crate magick_rust;
|
||||||
use magick_rust::bindings::MagickSetSeed;
|
//use magick_rust::{ColorspaceType, CompositeOperator, MagickWand, PixelWand, magick_wand_genesis, FilterType};
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::collections::HashMap;
|
use std::sync::Once;
|
||||||
use std::sync::{Arc, Once};
|
|
||||||
use tokio::sync::Mutex;
|
|
||||||
|
|
||||||
use palette::color_difference::ImprovedCiede2000;
|
//use palette::color_difference::ImprovedCiede2000;
|
||||||
use palette::lab::Lab;
|
//use palette::lab::Lab;
|
||||||
use palette::white_point::D65;
|
//use palette::white_point::D65;
|
||||||
|
|
||||||
extern crate sqlx;
|
extern crate sqlx;
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
|
||||||
use rspotify::model::{enums::types::SearchType, search::SearchResult};
|
|
||||||
use rspotify::{ClientCredsSpotify, Credentials, clients::BaseClient};
|
|
||||||
|
|
||||||
use imagetext::fontdb::FontDB;
|
use imagetext::fontdb::FontDB;
|
||||||
use imagetext::superfont::SuperFont;
|
use imagetext::superfont::SuperFont;
|
||||||
|
|
||||||
use std::time::SystemTime;
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
mod text;
|
mod text;
|
||||||
|
mod img;
|
||||||
|
|
||||||
static START: Once = Once::new();
|
static START: Once = Once::new();
|
||||||
|
|
||||||
@ -59,19 +56,19 @@ macro_rules! now {
|
|||||||
|
|
||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
($a:expr) => {
|
($a:expr) => {
|
||||||
if env::var("DEBUG").unwrap_or("0".to_owned()) == "1" {
|
if env::var("DEBUG").unwrap_or("0".to_string()) == "1" {
|
||||||
println!(concat!("debug: {} ", $a), now!())
|
println!(concat!("debug: {} ", $a), now!())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($a:expr, $($b:expr),+) => {
|
($a:expr, $($b:expr),+) => {
|
||||||
if env::var("DEBUG").unwrap_or("0".to_owned()) == "1" {
|
if env::var("DEBUG").unwrap_or("0".to_string()) == "1" {
|
||||||
println!(concat!("debug: {} ", $a), now!(), $($b),+)
|
println!(concat!("debug: {} ", $a), now!(), $($b),+)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! handle_magick_result {
|
macro_rules! handle_result {
|
||||||
($a: expr, $b: literal) => {
|
($a: expr, $b: literal) => {
|
||||||
match $a {
|
match $a {
|
||||||
Ok(a) => {
|
Ok(a) => {
|
||||||
@ -83,15 +80,16 @@ macro_rules! handle_magick_result {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! handle_magick_option {
|
macro_rules! handle_option {
|
||||||
($a: expr, $b: literal) => {
|
($a: expr, $b: literal) => {
|
||||||
match $a {
|
match $a {
|
||||||
Some(res) => res,
|
Some(res) => res,
|
||||||
None => return Reply::Text($b.to_owned()),
|
None => return Reply::Text($b.to_string()),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// this function is almost assuredly the least idiomatic rust code I will ever write.
|
// this function is almost assuredly the least idiomatic rust code I will ever write.
|
||||||
// but until I know what the "correct" way is, it'll have to do
|
// but until I know what the "correct" way is, it'll have to do
|
||||||
fn parse_cielab(s: String) -> Result<(f32, f32, f32), &'static str> {
|
fn parse_cielab(s: String) -> Result<(f32, f32, f32), &'static str> {
|
||||||
@ -112,9 +110,9 @@ fn parse_cielab(s: String) -> Result<(f32, f32, f32), &'static str> {
|
|||||||
&[a, b, c] => Ok((a, b, c)),
|
&[a, b, c] => Ok((a, b, c)),
|
||||||
_ => Err("Error parsing cielab string"),
|
_ => Err("Error parsing cielab string"),
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
fn validate_color(col: &PixelWand) -> Option<Lab> {
|
/*fn validate_color(col: &PixelWand) -> Option<Lab> {
|
||||||
let color_str = match col.get_color_as_string() {
|
let color_str = match col.get_color_as_string() {
|
||||||
Ok(s) => s,
|
Ok(s) => s,
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
@ -124,163 +122,85 @@ fn validate_color(col: &PixelWand) -> Option<Lab> {
|
|||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
};
|
};
|
||||||
Some(Lab::<D65>::from_components(color_raw))
|
Some(Lab::<D65>::from_components(color_raw))
|
||||||
}
|
}*/
|
||||||
|
|
||||||
async fn get_track(
|
const FMI_WIDTH: u32 = 548;
|
||||||
ctx: &Context,
|
const FMI_HEIGHT: u32 = 147;
|
||||||
arg: Option<&str>,
|
const FMI_GAP: u32 = 12;
|
||||||
id: UserId,
|
const FMI_AVATAR_SIZE: u32 = 64;
|
||||||
) -> Result<lastfm::track::NowPlayingTrack, Reply> {
|
const FMI_AVATAR_GAP: u32 = 10;
|
||||||
|
|
||||||
|
async fn fmi(ctx: &Context, arg: &str, id: UserId, avatar: Option<String>) -> Reply {
|
||||||
let lastfm_user = match arg {
|
let lastfm_user = match arg {
|
||||||
None => get_lastfm_username(ctx, id).await,
|
"" => get_lastfm_username(ctx, id).await,
|
||||||
Some(user) => Some(user.to_owned()),
|
_ => Some(arg.to_string()),
|
||||||
};
|
|
||||||
let lastfm_client = match lastfm_user {
|
|
||||||
Some(s) => lastfm::Client::<String, String>::from_env(s),
|
|
||||||
None => return Err(Reply::Text("No last.fm username set.".to_owned())),
|
|
||||||
};
|
};
|
||||||
|
let lastfm_client = lastfm::Client::<String, String>::from_env(handle_option!(lastfm_user, "No last.fm username set."));
|
||||||
let now_playing = match lastfm_client.now_playing().await {
|
let now_playing = match lastfm_client.now_playing().await {
|
||||||
Ok(np) => np,
|
Ok(np) => np,
|
||||||
Err(e) => {
|
Err(e) => return Reply::Text(format!("Error: grabbing last.fm user data failed {e}")),
|
||||||
return Err(Reply::Text(format!(
|
|
||||||
"Error: grabbing last.fm user data failed {e}"
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let track = match now_playing {
|
let track = match now_playing {
|
||||||
Some(track) => track,
|
Some(track) => track,
|
||||||
None => return Err(Reply::Text("Nothing playing.".to_owned())),
|
None => return Reply::Text("Nothing playing.".to_string()),
|
||||||
};
|
|
||||||
Ok(track)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn art(ctx: &Context, arg: Option<&str>, id: UserId) -> Reply {
|
|
||||||
let track = match get_track(ctx, arg, id).await {
|
|
||||||
Ok(track) => track,
|
|
||||||
Err(e) => return e,
|
|
||||||
};
|
|
||||||
let track_art = match track.image.extralarge {
|
|
||||||
Some(track_art) => track_art,
|
|
||||||
None => return Reply::Text("Error: getting image uri failed".to_owned()),
|
|
||||||
};
|
|
||||||
Reply::Text(track_art.to_owned())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn url(ctx: &Context, arg: Option<&str>, id: UserId) -> Reply {
|
|
||||||
let track = match get_track(ctx, arg, id).await {
|
|
||||||
Ok(track) => track,
|
|
||||||
Err(e) => return e,
|
|
||||||
};
|
|
||||||
Reply::Text(track.url)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn spot(ctx: &Context, arg: Option<&str>, id: UserId) -> Reply {
|
|
||||||
let track = match get_track(ctx, arg, id).await {
|
|
||||||
Ok(track) => track,
|
|
||||||
Err(e) => return e,
|
|
||||||
};
|
|
||||||
let mut data = ctx.data.write().await;
|
|
||||||
let spotify_option = data.get_mut::<SpotifyHaver>().expect("Failed to have spotify option");
|
|
||||||
if spotify_option.is_none() {
|
|
||||||
return Reply::Text("Unable to use Spotify commands: Contact bot Administrator.".to_owned())
|
|
||||||
}
|
|
||||||
let spotify_arc_mutex = spotify_option.as_mut().unwrap();
|
|
||||||
let spotify_client = spotify_arc_mutex.lock().await;
|
|
||||||
spotify_client.request_token().await.unwrap();
|
|
||||||
let search = spotify_client.search(format!("{} {}", track.name, track.artist.name).as_str(), SearchType::Track, None, None, None, None).await;
|
|
||||||
let tracks = match search {
|
|
||||||
Ok(SearchResult::Tracks(track_page)) => track_page,
|
|
||||||
Err(e) => return Reply::Text(format!("Failed to get track {e}")),
|
|
||||||
_ => return Reply::Text("Spotify search failed".to_owned()),
|
|
||||||
};
|
|
||||||
match &tracks.items.first().map(|x| x.external_urls.get("spotify")) {
|
|
||||||
Some(Some(url)) => Reply::Text(url.to_owned().to_owned()),
|
|
||||||
_ => Reply::Text("Unable to get spotify url".to_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_overrides_inner(last_modified: Option<SystemTime>) -> Option<HashMap<String, String>> {
|
|
||||||
let mut file = match std::fs::File::open("overrides.txt") {
|
|
||||||
Ok(a) => a,
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
|
||||||
let file_stats = match file.metadata() {
|
|
||||||
Ok(a) => a,
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
|
||||||
let file_modified_time = match file_stats.modified() {
|
|
||||||
Ok(a) => a,
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
|
||||||
let reload = match last_modified {
|
|
||||||
None => true,
|
|
||||||
Some(last_modified) => match file_modified_time.duration_since(last_modified) {
|
|
||||||
Err(_) => true,
|
|
||||||
Ok(a) => a != std::time::Duration::default()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if !reload { return None; }
|
|
||||||
let mut contents = "".to_owned();
|
|
||||||
match file.read_to_string(&mut contents) {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
|
||||||
Some(contents.as_str().lines().map(|x| {
|
|
||||||
let mut split = x.split("@");
|
|
||||||
let a: &str = split.next().unwrap_or("").trim();
|
|
||||||
let b: &str = split.next().unwrap_or("").trim();
|
|
||||||
(a.to_owned(), b.to_owned())
|
|
||||||
}).collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_overrides(ctx: &Context) -> HashMap<String, String> {
|
|
||||||
let data = ctx.data.write().await;
|
|
||||||
let overrides = data.get::<OverridesHaver>().expect("Failed to have overrides");
|
|
||||||
let mut map = overrides.map.lock().await;
|
|
||||||
let new_map = get_overrides_inner(overrides.last_modified).await;
|
|
||||||
if let Some(new_map) = new_map {
|
|
||||||
*map = new_map;
|
|
||||||
}
|
|
||||||
map.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String>) -> Reply {
|
|
||||||
let track = match get_track(ctx, arg, id).await {
|
|
||||||
Ok(track) => track,
|
|
||||||
Err(e) => return e,
|
|
||||||
};
|
};
|
||||||
|
#[allow(unused_variables)]
|
||||||
let track_info = text::TrackInfo {
|
let track_info = text::TrackInfo {
|
||||||
title: track.name,
|
title: track.name,
|
||||||
artist: track.artist.name,
|
artist: track.artist.name,
|
||||||
album: track.album,
|
album: track.album,
|
||||||
};
|
};
|
||||||
let original_image_uri = match track.image.extralarge {
|
let image_uri = match track.image.extralarge {
|
||||||
Some(iu) => iu,
|
Some(iu) => iu,
|
||||||
None => return Reply::Text("Error: getting image uri failed".to_owned()),
|
None => return Reply::Text("Error: getting image uri failed".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let overrides = get_overrides(ctx).await;
|
let image_base = match get_image(ctx, image_uri.as_str()).await {
|
||||||
let image_uri: String = match overrides.get(&format!("{} | {}", track_info.artist, track_info.album)) {
|
Ok(i) => i,
|
||||||
Some(s) => s,
|
Err(e) => return Reply::Text(e.to_string()),
|
||||||
None => match overrides.get(&track_info.album) {
|
};
|
||||||
Some(s) => s,
|
//let image_base_raw = Vec::<u8>::new();
|
||||||
None => &original_image_uri,
|
//let png_decoder = image::codecs::png::PngDecoder::new(&mut image_base);
|
||||||
},
|
//let mut image_rgba8 = Vec::<u8>::new();
|
||||||
}.to_owned();
|
//let png_encoder = image::codecs::png::PngEncoder::new(&mut image_rgba8);
|
||||||
|
//png_encoder.write_image(&image_base, image)
|
||||||
let mut base_color = PixelWand::new();
|
/*let mut base_color = PixelWand::new();
|
||||||
let mut accent_color = PixelWand::new();
|
|
||||||
let mut white = PixelWand::new();
|
let mut white = PixelWand::new();
|
||||||
let main_wand = MagickWand::new();
|
let main_wand = MagickWand::new();
|
||||||
let art_wand = MagickWand::new();
|
let art_wand = MagickWand::new();
|
||||||
let mut art_wand_cluster = MagickWand::new();
|
let mut art_wand_cluster = MagickWand::new();
|
||||||
let mask_wand = MagickWand::new();
|
let mask_wand = MagickWand::new();
|
||||||
let text_image_wand = MagickWand::new();
|
let text_image_wand = MagickWand::new();*/
|
||||||
|
let mut main_image = handle_option!(tiny_skia::Pixmap::new(FMI_WIDTH, FMI_HEIGHT), "Failed to load main image");
|
||||||
let image = match get_image(ctx, image_uri.as_str()).await {
|
let mut album_image = handle_result!(tiny_skia::Pixmap::decode_png(&image_base), "Failed to load album art image");
|
||||||
Ok(i) => i,
|
//let album_image = handle_result!(tiny_skia::Pixmap::decode_png(&image_rgba8), "Failed to decode album art");
|
||||||
Err(e) => return Reply::Text(format!("{e}")),
|
#[allow(unused_variables)]
|
||||||
|
let (dom, sub) = match img::dominant_colors_as_paints(&album_image) {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(e) => return Reply::Text(e),
|
||||||
};
|
};
|
||||||
|
//let background_paint = handle_result!(img::color_paint_from_lab_color(dom), "Failed to create color paint");
|
||||||
|
main_image.fill_rect(tiny_skia::Rect::from_xywh(0.0, 0.0, FMI_WIDTH as f32, FMI_HEIGHT as f32).unwrap(), &dom, tiny_skia::Transform::identity(), None);
|
||||||
|
let mut pb = tiny_skia::PathBuilder::new();
|
||||||
|
pb.move_to(FMI_WIDTH as f32, 0.0);
|
||||||
|
pb.line_to((FMI_WIDTH - FMI_HEIGHT) as f32, FMI_HEIGHT as f32);
|
||||||
|
pb.line_to(FMI_WIDTH as f32, FMI_HEIGHT as f32);
|
||||||
|
pb.close();
|
||||||
|
let path = pb.finish().unwrap();
|
||||||
|
main_image.fill_path(&path, &sub, tiny_skia::FillRule::Winding, tiny_skia::Transform::identity(), None);
|
||||||
|
let art_size = FMI_HEIGHT- 2 * FMI_GAP;
|
||||||
|
album_image = handle_option!(img::scale_skia_pixmap(album_image, art_size, art_size), "Failed to scale bitmap");
|
||||||
|
//let art_scale_matrix = tiny_skia::Transform::from_transla(art_size, art_size).pre_translate(FMI_GAP as f32, FMI_GAP as f32);
|
||||||
|
let source_paint = tiny_skia::PixmapPaint {
|
||||||
|
opacity: 1.0,
|
||||||
|
blend_mode: tiny_skia::BlendMode::SourceOver,
|
||||||
|
quality: tiny_skia::FilterQuality::Bilinear,
|
||||||
|
};
|
||||||
|
main_image.draw_pixmap(FMI_GAP as i32, FMI_GAP as i32, album_image.as_ref(), &source_paint, tiny_skia::Transform::identity(), None);
|
||||||
|
/*handle_magick_result!(
|
||||||
|
base_color.set_color("#7f7f7f"),
|
||||||
|
"Failed to set init base color"
|
||||||
|
);
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
art_wand.read_image_blob(image),
|
art_wand.read_image_blob(image),
|
||||||
"Failed to read image from uri"
|
"Failed to read image from uri"
|
||||||
@ -290,26 +210,6 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
"Failed to set art colorspace"
|
"Failed to set art colorspace"
|
||||||
);
|
);
|
||||||
|
|
||||||
handle_magick_result!(
|
|
||||||
base_color.set_color("#7f7f7f"),
|
|
||||||
"Failed to set init base color"
|
|
||||||
);
|
|
||||||
|
|
||||||
let color_cache_entry = {
|
|
||||||
let data = ctx.data.write().await;
|
|
||||||
let color_cache = data.get::<ColorsHaver>().expect("Failed to have colors option");
|
|
||||||
if color_cache.max > 0 {
|
|
||||||
let color_cache_map = color_cache.map.lock().await;
|
|
||||||
color_cache_map.get(image_uri.as_str()).map(|s| s.to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
let (base_lab, accent_lab) = match color_cache_entry {
|
|
||||||
Some(value) => value.to_owned(),
|
|
||||||
None => {
|
|
||||||
let (art_width, art_height) = (art_wand.get_image_width(), art_wand.get_image_height());
|
let (art_width, art_height) = (art_wand.get_image_width(), art_wand.get_image_height());
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
art_wand_cluster.new_image(art_width, art_height, &base_color),
|
art_wand_cluster.new_image(art_width, art_height, &base_color),
|
||||||
@ -324,7 +224,6 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
art_wand_cluster.set_image_colorspace(ColorspaceType::Lab),
|
art_wand_cluster.set_image_colorspace(ColorspaceType::Lab),
|
||||||
"Failed to set cluster colorspace"
|
"Failed to set cluster colorspace"
|
||||||
);
|
);
|
||||||
unsafe { MagickSetSeed(0x5F3759DF); }
|
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
art_wand_cluster.kmeans(10, 200, 0.001),
|
art_wand_cluster.kmeans(10, 200, 0.001),
|
||||||
"Failed to run kmeans"
|
"Failed to run kmeans"
|
||||||
@ -345,33 +244,27 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut accent_lab = "cielab(0.0,0.0,0.0)".to_owned();
|
let mut accent_color = PixelWand::new();
|
||||||
|
handle_magick_result!(
|
||||||
|
accent_color.set_color("cielab(0.0,0.0,0.0)"),
|
||||||
|
"Failed to init accent color"
|
||||||
|
);
|
||||||
if let Some(color) = other_colors.first() {
|
if let Some(color) = other_colors.first() {
|
||||||
accent_lab = format!("cielab{:?}", color.into_components());
|
let col = format!("cielab{:?}", color.into_components());
|
||||||
|
handle_magick_result!(
|
||||||
|
accent_color.set_color(col.as_str()),
|
||||||
|
"Failed to set accent color"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
let base_lab = handle_magick_result!(colors[0].get_color_as_string(), "Failed to serialize base color");
|
|
||||||
let data = ctx.data.write().await;
|
|
||||||
let color_cache = data.get::<ColorsHaver>().expect("Failed to have colors option");
|
|
||||||
let mut color_cache_map = color_cache.map.lock().await;
|
|
||||||
if color_cache_map.keys().len() > color_cache.max {
|
|
||||||
let key: String = color_cache_map.iter().next().unwrap().0.to_owned();
|
|
||||||
color_cache_map.remove(&key);
|
|
||||||
}
|
|
||||||
color_cache_map.insert(image_uri, (base_lab.clone(), accent_lab.clone()));
|
|
||||||
(base_lab, accent_lab)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
handle_magick_result!(base_color.set_color(base_lab.as_str()), "Failed to deserialize base color");
|
|
||||||
handle_magick_result!(accent_color.set_color(accent_lab.as_str()), "Failed to deserialize accent color");
|
|
||||||
|
|
||||||
let use_dark_color = match validate_color(&base_color) {
|
let use_dark_color = match validate_color(&colors[0]) {
|
||||||
Some(color) => {
|
Some(color) => {
|
||||||
let black_delta_e = Lab::<D65>::new(0.0, 0.0, 0.0).improved_difference(color);
|
let black_delta_e = Lab::<D65>::new(0.0, 0.0, 0.0).improved_difference(color);
|
||||||
let white_delta_e = Lab::<D65>::new(100.0, 0.0, 0.0).improved_difference(color);
|
let white_delta_e = Lab::<D65>::new(100.0, 0.0, 0.0).improved_difference(color);
|
||||||
black_delta_e > white_delta_e
|
black_delta_e > white_delta_e
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false
|
||||||
};
|
};
|
||||||
|
|
||||||
handle_magick_result!(white.set_color("#ffffff"), "Failed to init white");
|
handle_magick_result!(white.set_color("#ffffff"), "Failed to init white");
|
||||||
@ -403,8 +296,21 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
avatar_wand.new_image(100, 100, &white),
|
avatar_wand.new_image(100, 100, &white),
|
||||||
"Failed to load dummy avatar"
|
"Failed to load dummy avatar"
|
||||||
),
|
),
|
||||||
}
|
}*/
|
||||||
let avatar_mask_wand = MagickWand::new();
|
let avatar_uri = avatar.unwrap(); // TODO: FIX THIS
|
||||||
|
let avatar_base = match get_image(ctx, avatar_uri.as_str()).await {
|
||||||
|
Ok(i) => i,
|
||||||
|
Err(e) => return Reply::Text(e.to_string()),
|
||||||
|
};
|
||||||
|
let mut avatar_image = handle_result!(tiny_skia::Pixmap::decode_png(&avatar_base), "Failed to load album art image");
|
||||||
|
let avatar_mask = handle_result!(tiny_skia::Mask::decode_png(include_bytes!("avatar_mask.png")), "Failed to load album art image");
|
||||||
|
let (avatar_x, avatar_y) = (FMI_WIDTH - FMI_AVATAR_SIZE - FMI_AVATAR_GAP, FMI_HEIGHT - FMI_AVATAR_SIZE - FMI_AVATAR_GAP);
|
||||||
|
avatar_image.apply_mask(&avatar_mask);
|
||||||
|
avatar_image = handle_option!(img::scale_skia_pixmap(avatar_image, FMI_AVATAR_SIZE, FMI_AVATAR_SIZE), "Failed to scale avatar image");
|
||||||
|
//let avatar_matrix = tiny_skia::Transform::from_scale(avatar_scale, avatar_scale).pre_translate(avatar_x as f32, avatar_y as f32);
|
||||||
|
main_image.draw_pixmap(avatar_x as i32, avatar_y as i32, avatar_image.as_ref(), &source_paint, tiny_skia::Transform::identity(), None);
|
||||||
|
|
||||||
|
/*let avatar_mask_wand = MagickWand::new();
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
avatar_mask_wand.read_image_blob(include_bytes!("avatar_mask.png")),
|
avatar_mask_wand.read_image_blob(include_bytes!("avatar_mask.png")),
|
||||||
"Failed to load avatar mask"
|
"Failed to load avatar mask"
|
||||||
@ -424,29 +330,20 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
|
|
||||||
let (image_width, image_height) = (548, 147);
|
let (image_width, image_height) = (548, 147);
|
||||||
let data = ctx.data.write().await;
|
let data = ctx.data.write().await;
|
||||||
let fonts = data.get::<FontsHaver>().expect("Failed to load fonts");
|
let fonts = data
|
||||||
let text_image_blob = match text::fmi_text(
|
.get::<FontsHaver>().expect("Failed to load fonts");
|
||||||
image_width,
|
let text_image_blob = match text::fmi_text(image_width, image_height, track_info, fonts, 19.0, use_dark_color) {
|
||||||
image_height,
|
|
||||||
track_info,
|
|
||||||
fonts,
|
|
||||||
19.0,
|
|
||||||
use_dark_color,
|
|
||||||
) {
|
|
||||||
Ok(bytes) => bytes,
|
Ok(bytes) => bytes,
|
||||||
Err(e) => return Reply::Text(e),
|
Err(e) => return Reply::Text(e),
|
||||||
};
|
};
|
||||||
handle_magick_result!(
|
handle_magick_result!(text_image_wand.read_image_blob(&text_image_blob), "Failed to load text image");
|
||||||
text_image_wand.read_image_blob(&text_image_blob),
|
|
||||||
"Failed to load text image"
|
|
||||||
);
|
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
text_image_wand.transform_image_colorspace(ColorspaceType::Lab),
|
text_image_wand.transform_image_colorspace(ColorspaceType::Lab),
|
||||||
"Failed to set avatar colorspace"
|
"Failed to set avatar colorspace"
|
||||||
);
|
);
|
||||||
|
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
main_wand.new_image(image_width as usize, image_height as usize, &base_color),
|
main_wand.new_image(image_width as usize, image_height as usize, &colors[0]),
|
||||||
"Failed to create wand"
|
"Failed to create wand"
|
||||||
);
|
);
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
@ -454,13 +351,13 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
"Failed to set main colorspace"
|
"Failed to set main colorspace"
|
||||||
);
|
);
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
art_wand.resize_image(124, 124, FilterType::RobidouxSharp),
|
art_wand.adaptive_resize_image(124, 124),
|
||||||
"Failed to resize art"
|
"Failed to resize art"
|
||||||
);
|
);
|
||||||
/*handle_magick_result!(
|
handle_magick_result!(
|
||||||
art_wand_cluster.adaptive_resize_image(124, 124),
|
art_wand_cluster.adaptive_resize_image(124, 124),
|
||||||
"Failed to resize art_cluster"
|
"Failed to resize art_cluster"
|
||||||
);*/
|
);
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
main_wand.compose_images(&art_wand, CompositeOperator::SrcOver, false, 12, 12),
|
main_wand.compose_images(&art_wand, CompositeOperator::SrcOver, false, 12, 12),
|
||||||
"Failed to combine art image"
|
"Failed to combine art image"
|
||||||
@ -470,7 +367,7 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
"Failed to combine mask"
|
"Failed to combine mask"
|
||||||
);
|
);
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
if env::var("DEBUG_IMAGE").unwrap_or("0".to_owned()) == "1" {
|
if env::var("DEBUG_IMAGE").unwrap_or("0".to_string()) == "1" {
|
||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
main_wand.compose_images(
|
main_wand.compose_images(
|
||||||
&art_wand_cluster,
|
&art_wand_cluster,
|
||||||
@ -489,142 +386,31 @@ async fn fmi(ctx: &Context, arg: Option<&str>, id: UserId, avatar: Option<String
|
|||||||
handle_magick_result!(
|
handle_magick_result!(
|
||||||
main_wand.compose_images(&avatar_wand, CompositeOperator::SrcOver, false, 473, 73),
|
main_wand.compose_images(&avatar_wand, CompositeOperator::SrcOver, false, 473, 73),
|
||||||
"Failed to combine avatar image"
|
"Failed to combine avatar image"
|
||||||
);
|
);*/
|
||||||
Reply::Image(main_wand.write_image_blob("png").unwrap())
|
//Reply::Image(main_wand.write_image_blob("png").unwrap())
|
||||||
}
|
Reply::Image(main_image.encode_png().unwrap())
|
||||||
|
|
||||||
async fn text(ctx: &Context, arg: Option<&str>, id: UserId) -> Reply {
|
|
||||||
let track = match get_track(ctx, arg, id).await {
|
|
||||||
Ok(track) => track,
|
|
||||||
Err(e) => return e,
|
|
||||||
};
|
|
||||||
Reply::Text(format!(
|
|
||||||
"{}\n{}\n{}",
|
|
||||||
track.name,
|
|
||||||
track.artist.name,
|
|
||||||
track.album,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn help(arg: Option<&str>) -> Reply {
|
|
||||||
Reply::Text(format!(
|
|
||||||
"```{}```",
|
|
||||||
match arg {
|
|
||||||
None =>
|
|
||||||
"usage: .k <img|set|art|url|spotify|help> [lastfm user]\n .k img [lastfm user]: get now playing\n .k set <lastfm user>: sets your username for the future\n .k art [lastfm user]: get now playing album art\n .k url [lastfm user]: get now playing lastfm url\n .k spot [lastfm user]: get now playing spotify link\n .k search <search query>: searches spotify\n .k help [command]: displays a help message"
|
|
||||||
.to_owned(),
|
|
||||||
Some("img" | "fmi" | "fm" | "get") =>
|
|
||||||
"usage: .k img [lastfm user]\nreturns a pretty-printed image of the user's now playing track on last.fm, using the album art's colors to theme the image. see also: .k set\naliases: .kfmi, .k <fmi|get|img>, .kf, .ki, or even just .k"
|
|
||||||
.to_owned(),
|
|
||||||
Some("set") =>
|
|
||||||
"usage: .k set <lastfm user>\nties a lastfm username to your account. use this to not require your username for .k fmi every time, for example\naliases: .kset"
|
|
||||||
.to_owned(),
|
|
||||||
Some("art") =>
|
|
||||||
"usage: .k art [lastfm user]\nfetches user's now playing track's album art\naliases: .k art, .kart, .ka"
|
|
||||||
.to_owned(),
|
|
||||||
Some("url" | "link") =>
|
|
||||||
"usage: .k url [lastfm user]\nfetches a lastfm link to user's now playing track\naliases: .k url, .k link, .kl, .ku, .kurl"
|
|
||||||
.to_owned(),
|
|
||||||
Some("spot" | "spotify") =>
|
|
||||||
"usage: .k spotify [lastfm user]\nsearches spotify for the user's now playing track and returns a link to that track\naliases: .k <spot|spotify>, .kx, .kspot"
|
|
||||||
.to_owned(),
|
|
||||||
Some("search") =>
|
|
||||||
"usage: .k search <search query>\nsearches spotify with an arbitrary query and returns the first result\naliases: .k search, .ks".to_owned(),
|
|
||||||
Some(cmd) => format!("unknown command: {cmd}"),
|
|
||||||
}
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set(ctx: &Context, arg: &str, id: UserId) -> Reply {
|
async fn set(ctx: &Context, arg: &str, id: UserId) -> Reply {
|
||||||
set_lastfm_username(ctx, id, arg.to_owned()).await;
|
set_lastfm_username(ctx, id, arg.to_string()).await;
|
||||||
Reply::Text(format!("set user {arg}"))
|
Reply::Text(format!("set user {}", arg))
|
||||||
}
|
|
||||||
|
|
||||||
async fn search(ctx: &Context, arg: &str) -> Reply {
|
|
||||||
let mut data = ctx.data.write().await;
|
|
||||||
let spotify_option = data.get_mut::<SpotifyHaver>().expect("Failed to have spotify option");
|
|
||||||
if spotify_option.is_none() {
|
|
||||||
return Reply::Text("Unable to use Spotify commands: Contact bot Administrator.".to_owned())
|
|
||||||
}
|
|
||||||
let spotify_arc_mutex = spotify_option.as_mut().unwrap();
|
|
||||||
let spotify_client = spotify_arc_mutex.lock().await;
|
|
||||||
spotify_client.request_token().await.unwrap();
|
|
||||||
let search = spotify_client.search(arg, SearchType::Track, None, None, None, None).await;
|
|
||||||
let tracks = match search {
|
|
||||||
Ok(SearchResult::Tracks(track_page)) => track_page,
|
|
||||||
Err(e) => return Reply::Text(format!("Failed to get track {e}")),
|
|
||||||
_ => return Reply::Text("Spotify search failed".to_owned()),
|
|
||||||
};
|
|
||||||
match &tracks.items.first().map(|x| x.external_urls.get("spotify")) {
|
|
||||||
Some(Some(url)) => Reply::Text(url.to_owned().to_owned()),
|
|
||||||
_ => Reply::Text("Unable to get spotify url".to_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! cmd_pattern {
|
|
||||||
($long_cmd:pat, $short_pattern:pat, $arg_name:pat) => {
|
|
||||||
(Some(".k"), Some($long_cmd), $arg_name) | (Some(".k"), $arg_name, Some($long_cmd)) | (Some($short_pattern), $arg_name, None)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn message(&self, ctx: Context, msg: Message) {
|
async fn message(&self, ctx: Context, msg: Message) {
|
||||||
let mut cmd_iter = msg.content.split(" ");
|
let mut cmd_iter = msg.content.split(" ");
|
||||||
let cmd = cmd_iter.next();
|
let cmd = cmd_iter.next().unwrap_or("");
|
||||||
let arg1 = cmd_iter.next();
|
let arg = cmd_iter.next().unwrap_or("");
|
||||||
let arg2 = cmd_iter.next();
|
let resp = match cmd {
|
||||||
let resp = match (cmd, arg1, arg2) {
|
".fmi" => {
|
||||||
(Some(".k"), Some("help" | "h" | "?"), arg) // skip the ".k <command> help" syntax
|
|
||||||
| (Some(".kh") | Some(".k?"), arg, None) => {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(help(arg))
|
|
||||||
}
|
|
||||||
cmd_pattern!("set", ".kset" | ".set", Some(arg)) =>
|
|
||||||
/*(".set", arg, "") | (".k", "set", arg) | (".kset", arg, "") =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(set(&ctx, arg, msg.author.id).await)
|
|
||||||
},
|
|
||||||
cmd_pattern!("art", ".ka" | ".kart", arg) =>
|
|
||||||
/*(".k", "art", arg) | (".k", arg, "art") | (".ka" | ".kart", arg, "") =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(art(&ctx, arg, msg.author.id).await)
|
|
||||||
},
|
|
||||||
cmd_pattern!("url" | "uri" | "link", ".ku" | ".kl", arg) =>
|
|
||||||
/*(".k", "url" | "uri" | "link", arg)
|
|
||||||
| (".k", arg, "url" | "uri" | "link")
|
|
||||||
| (".ku" | ".kl" | ".kurl", arg, "") =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(url(&ctx, arg, msg.author.id).await)
|
|
||||||
},
|
|
||||||
cmd_pattern!("text", ".kt", arg) =>
|
|
||||||
/*(".k", "url" | "uri" | "link", arg)
|
|
||||||
| (".k", arg, "url" | "uri" | "link")
|
|
||||||
| (".ku" | ".kl" | ".kurl", arg, "") =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(text(&ctx, arg, msg.author.id).await)
|
|
||||||
},
|
|
||||||
cmd_pattern!("spot" | "spotify", ".kx", arg) =>
|
|
||||||
/*(".k", "spot" | "spotify", arg)
|
|
||||||
| (".k", arg, "spot" | "spotify")
|
|
||||||
| (".ks" | ".kspot", arg, "") =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(spot(&ctx, arg, msg.author.id).await)
|
|
||||||
},
|
|
||||||
(Some(".ks"), Some(_), _) => {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(search(&ctx, &msg.content[4..]).await)
|
|
||||||
},
|
|
||||||
(Some(".k"), Some("search"), Some(_)) => {
|
|
||||||
log!("{} received", msg.content);
|
|
||||||
Some(search(&ctx, &msg.content[10..]).await)
|
|
||||||
},
|
|
||||||
cmd_pattern!("fm" | "fmi" | "get" | "img", ".fmi" | ".k" | ".kf" | ".ki" | ".kfmi", arg) =>
|
|
||||||
/*(".fmi" | ".k" | ".kf" | ".ki" | ".kfmi", arg, "")
|
|
||||||
| (".k", "fm" | "fmi" | "get" | "img", arg) =>*/ {
|
|
||||||
log!("{} received", msg.content);
|
log!("{} received", msg.content);
|
||||||
Some(fmi(&ctx, arg, msg.author.id, msg.author.avatar_url()).await)
|
Some(fmi(&ctx, arg, msg.author.id, msg.author.avatar_url()).await)
|
||||||
}
|
}
|
||||||
|
".set" => {
|
||||||
|
log!("{} received", msg.content);
|
||||||
|
Some(set(&ctx, arg, msg.author.id).await)
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
if let Some(reply) = resp {
|
if let Some(reply) = resp {
|
||||||
@ -659,29 +445,6 @@ impl TypeMapKey for FontsHaver {
|
|||||||
type Value = (SuperFont<'static>, SuperFont<'static>);
|
type Value = (SuperFont<'static>, SuperFont<'static>);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SpotifyHaver;
|
|
||||||
impl TypeMapKey for SpotifyHaver {
|
|
||||||
type Value = Option<Arc<Mutex<ClientCredsSpotify>>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ColorCache {
|
|
||||||
map: Arc<Mutex<HashMap<String, (String, String)>>>,
|
|
||||||
max: usize,
|
|
||||||
}
|
|
||||||
struct ColorsHaver;
|
|
||||||
impl TypeMapKey for ColorsHaver {
|
|
||||||
type Value = ColorCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Overrides {
|
|
||||||
map: Arc<Mutex<HashMap<String, String>>>,
|
|
||||||
last_modified: Option<SystemTime>,
|
|
||||||
}
|
|
||||||
struct OverridesHaver;
|
|
||||||
impl TypeMapKey for OverridesHaver {
|
|
||||||
type Value = Overrides;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DBResponse {
|
struct DBResponse {
|
||||||
lastfm_username: String,
|
lastfm_username: String,
|
||||||
}
|
}
|
||||||
@ -715,7 +478,7 @@ async fn get_lastfm_username(ctx: &Context, id: UserId) -> Option<String> {
|
|||||||
|
|
||||||
async fn set_lastfm_username(ctx: &Context, id: UserId, user: String) {
|
async fn set_lastfm_username(ctx: &Context, id: UserId, user: String) {
|
||||||
log!("set db user {} {}", id, user);
|
log!("set db user {} {}", id, user);
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.write().await;
|
||||||
let pool = data
|
let pool = data
|
||||||
.get::<PoolHaver>()
|
.get::<PoolHaver>()
|
||||||
.expect("Failed to get pool container");
|
.expect("Failed to get pool container");
|
||||||
@ -733,20 +496,23 @@ async fn set_lastfm_username(ctx: &Context, id: UserId, user: String) {
|
|||||||
.expect("Failed to insert");
|
.expect("Failed to insert");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_image(ctx: &Context, url: &str) -> Result<Vec<u8>, reqwest_middleware::Error> {
|
async fn get_image(ctx: &Context, url: &str) -> Result<Vec<u8>, String> {
|
||||||
log!("get {}", url);
|
log!("get {}", url);
|
||||||
let data = ctx.data.read().await;
|
let data = ctx.data.write().await;
|
||||||
let http = data.get::<HttpHaver>().expect("Failed to get http client");
|
let http = data
|
||||||
|
.get::<HttpHaver>()
|
||||||
|
.expect("Failed to get http client");
|
||||||
match http.get(url).send().await {
|
match http.get(url).send().await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
log!("response received");
|
log!("response received");
|
||||||
Ok(resp
|
let img_raw = resp
|
||||||
.bytes()
|
.bytes()
|
||||||
.await
|
.await
|
||||||
.expect("Unable to resolve bytes")
|
.expect("Unable to resolve bytes")
|
||||||
.to_vec())
|
.to_vec();
|
||||||
|
img::ensure_32_bit_png(&img_raw)
|
||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(format!("{e}")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,7 +520,7 @@ async fn get_image(ctx: &Context, url: &str) -> Result<Vec<u8>, reqwest_middlewa
|
|||||||
async fn main() {
|
async fn main() {
|
||||||
START.call_once(|| {
|
START.call_once(|| {
|
||||||
dotenvy::dotenv().expect("Failed to load .env");
|
dotenvy::dotenv().expect("Failed to load .env");
|
||||||
magick_wand_genesis();
|
//magick_wand_genesis();
|
||||||
});
|
});
|
||||||
|
|
||||||
let db_url = env::var("DATABASE_URL").expect("Failed to load DATABASE_URL");
|
let db_url = env::var("DATABASE_URL").expect("Failed to load DATABASE_URL");
|
||||||
@ -777,8 +543,7 @@ async fn main() {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
FontDB::load_from_dir("fonts"); //singlet instance??? wha?????
|
FontDB::load_from_dir("fonts"); //singlet instance??? wha?????
|
||||||
let regular_fonts = FontDB::query(
|
let regular_fonts = FontDB::query("
|
||||||
"
|
|
||||||
NotoSans-Regular
|
NotoSans-Regular
|
||||||
NotoSansHK-Regular
|
NotoSansHK-Regular
|
||||||
NotoSansJP-Regular
|
NotoSansJP-Regular
|
||||||
@ -790,11 +555,8 @@ async fn main() {
|
|||||||
NotoEmoji-Regular
|
NotoEmoji-Regular
|
||||||
Symbola
|
Symbola
|
||||||
Unifont
|
Unifont
|
||||||
",
|
").expect("Failed to load regular fonts");
|
||||||
)
|
let bold_fonts = FontDB::query("
|
||||||
.expect("Failed to load regular fonts");
|
|
||||||
let bold_fonts = FontDB::query(
|
|
||||||
"
|
|
||||||
NotoSans-SemiBold
|
NotoSans-SemiBold
|
||||||
NotoSansJP-Medium
|
NotoSansJP-Medium
|
||||||
NotoSansKR-Medium
|
NotoSansKR-Medium
|
||||||
@ -805,25 +567,7 @@ async fn main() {
|
|||||||
NotoEmoji-Medium
|
NotoEmoji-Medium
|
||||||
Symbola
|
Symbola
|
||||||
Unifont
|
Unifont
|
||||||
",
|
").expect("Failed to load bold fonts");
|
||||||
)
|
|
||||||
.expect("Failed to load bold fonts");
|
|
||||||
|
|
||||||
let spotify_creds = Credentials::from_env();
|
|
||||||
let spotify = spotify_creds.map(ClientCredsSpotify::new);
|
|
||||||
if let Some(spotify_client) = &spotify {
|
|
||||||
let _ = &spotify_client.request_token().await.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let colors_cache = ColorCache {
|
|
||||||
map: Arc::new(Mutex::new(HashMap::new())),
|
|
||||||
max: env::var("MAX_CACHE_SIZE").unwrap_or("".to_owned()).parse::<usize>().unwrap_or(1000000),
|
|
||||||
};
|
|
||||||
|
|
||||||
let overrides = Overrides {
|
|
||||||
map: Arc::new(Mutex::new(HashMap::new())),
|
|
||||||
last_modified: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut discord_client = Client::builder(&token, intents)
|
let mut discord_client = Client::builder(&token, intents)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
@ -835,9 +579,6 @@ async fn main() {
|
|||||||
data.insert::<PoolHaver>(pool);
|
data.insert::<PoolHaver>(pool);
|
||||||
data.insert::<HttpHaver>(http);
|
data.insert::<HttpHaver>(http);
|
||||||
data.insert::<FontsHaver>((regular_fonts, bold_fonts));
|
data.insert::<FontsHaver>((regular_fonts, bold_fonts));
|
||||||
data.insert::<SpotifyHaver>(spotify.map(Mutex::new).map(Arc::new));
|
|
||||||
data.insert::<ColorsHaver>(colors_cache);
|
|
||||||
data.insert::<OverridesHaver>(overrides);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(why) = discord_client.start().await {
|
if let Err(why) = discord_client.start().await {
|
||||||
|
|||||||
67
src/text.rs
67
src/text.rs
@ -1,16 +1,19 @@
|
|||||||
|
/*
|
||||||
// this code is mostly just blindly ported from
|
// this code is mostly just blindly ported from
|
||||||
// https://github.com/adamanldo/Cosmo/blob/946af25dcac8a81cb7b49d1a4f83731a5f7c7b46/cogs/utils/fmi_text.py
|
// https://github.com/adamanldo/Cosmo/blob/946af25dcac8a81cb7b49d1a4f83731a5f7c7b46/cogs/utils/fmi_text.py
|
||||||
// since I'm using the same text rendering library, my code is almost one-to-one
|
// since I'm using the same text rendering library, my code is almost one-to-one
|
||||||
|
|
||||||
use arabic_reshaper::arabic_reshape;
|
use arabic_reshaper::arabic_reshape;
|
||||||
use image::codecs::png::PngEncoder;
|
|
||||||
use image::{ExtendedColorType, ImageEncoder, RgbaImage};
|
|
||||||
use imagetext::measure::text_width;
|
use imagetext::measure::text_width;
|
||||||
use imagetext::prelude::{BLACK, Outline, TextAlign, WHITE, draw_text_wrapped, scale, stroke};
|
|
||||||
use imagetext::superfont::SuperFont;
|
use imagetext::superfont::SuperFont;
|
||||||
use imagetext::wrap::{WrapStyle, text_wrap};
|
use imagetext::wrap::{text_wrap, WrapStyle};
|
||||||
|
use imagetext::prelude::{scale, BLACK, WHITE, Outline, draw_text_wrapped, TextAlign, stroke};
|
||||||
|
use image::{RgbaImage, ExtendedColorType, ImageEncoder};
|
||||||
|
use image::codecs::png::PngEncoder;
|
||||||
use unicode_bidi::BidiInfo;
|
use unicode_bidi::BidiInfo;
|
||||||
|
|
||||||
|
use crate::img;
|
||||||
|
|
||||||
enum TextField {
|
enum TextField {
|
||||||
Title,
|
Title,
|
||||||
Artist,
|
Artist,
|
||||||
@ -68,14 +71,7 @@ fn process_text(
|
|||||||
(wrapped_strs, width)
|
(wrapped_strs, width)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_info(
|
fn draw_info(image: &mut RgbaImage, text: String, text_type: TextField, font: &SuperFont<'static>, font_size: f32, dark_text: bool) -> Result<(), String> {
|
||||||
image: &mut RgbaImage,
|
|
||||||
text: String,
|
|
||||||
text_type: TextField,
|
|
||||||
font: &SuperFont<'static>,
|
|
||||||
font_size: f32,
|
|
||||||
dark_text: bool,
|
|
||||||
) -> Result<(), String> {
|
|
||||||
let (lines, width) = process_text(&text, &text_type, font, font_size);
|
let (lines, width) = process_text(&text, &text_type, font, font_size);
|
||||||
let text = lines.join("");
|
let text = lines.join("");
|
||||||
let y = match text_type {
|
let y = match text_type {
|
||||||
@ -106,51 +102,20 @@ fn draw_info(
|
|||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct TrackInfo {
|
pub struct TrackInfo {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub artist: String,
|
pub artist: String,
|
||||||
pub album: String,
|
pub album: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fmi_text(
|
/*pub fn fmi_text(width: u32, height: u32, track: TrackInfo, fonts: &(SuperFont<'static>, SuperFont<'static>), font_size: f32, dark_text: bool) -> Result<Vec<u8>, String> {
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
track: TrackInfo,
|
|
||||||
fonts: &(SuperFont<'static>, SuperFont<'static>),
|
|
||||||
font_size: f32,
|
|
||||||
dark_text: bool,
|
|
||||||
) -> Result<Vec<u8>, String> {
|
|
||||||
let mut img = RgbaImage::new(width, height);
|
let mut img = RgbaImage::new(width, height);
|
||||||
draw_info(
|
draw_info(&mut img, track.title, TextField::Title, &fonts.1.clone(), font_size, dark_text)?;
|
||||||
&mut img,
|
draw_info(&mut img, track.artist, TextField::Artist, &fonts.0.clone(), font_size, dark_text)?;
|
||||||
track.title,
|
draw_info(&mut img, track.album, TextField::Album, &fonts.0.clone(), font_size, dark_text)?;
|
||||||
TextField::Title,
|
img::save_to_memory_png(&img)
|
||||||
&fonts.1.clone(),
|
|
||||||
font_size,
|
|
||||||
dark_text,
|
|
||||||
)?;
|
|
||||||
draw_info(
|
|
||||||
&mut img,
|
|
||||||
track.artist,
|
|
||||||
TextField::Artist,
|
|
||||||
&fonts.0.clone(),
|
|
||||||
font_size,
|
|
||||||
dark_text,
|
|
||||||
)?;
|
|
||||||
draw_info(
|
|
||||||
&mut img,
|
|
||||||
track.album,
|
|
||||||
TextField::Album,
|
|
||||||
&fonts.0.clone(),
|
|
||||||
font_size,
|
|
||||||
dark_text,
|
|
||||||
)?;
|
|
||||||
let mut blob = Vec::<u8>::new();
|
|
||||||
let png_encoder = PngEncoder::new(&mut blob);
|
|
||||||
match png_encoder.write_image(&img, width, height, ExtendedColorType::Rgba8) {
|
|
||||||
Ok(()) => Ok(blob),
|
|
||||||
Err(_) => Err("Failed to encode text png".to_string()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user