fix attachments. remove webhook sending for speedup

This commit is contained in:
jude 2022-04-09 12:21:28 +01:00
parent 0f05018cab
commit 4c4f0927f1
11 changed files with 370 additions and 231 deletions

237
Cargo.lock generated
View File

@ -49,7 +49,7 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [ dependencies = [
"getrandom 0.2.5", "getrandom 0.2.6",
"once_cell", "once_cell",
"version_check", "version_check",
] ]
@ -95,9 +95,9 @@ dependencies = [
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.52" version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -106,18 +106,18 @@ dependencies = [
[[package]] [[package]]
name = "async-tungstenite" name = "async-tungstenite"
version = "0.16.1" version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5682ea0913e5c20780fe5785abacb85a411e7437bf52a1bedb93ddb3972cb8dd" checksum = "a1b71b31561643aa8e7df3effe284fa83ab1a840e52294c5f4bd7bfd8b2becbb"
dependencies = [ dependencies = [
"futures-io", "futures-io",
"futures-util", "futures-util",
"log", "log",
"pin-project-lite", "pin-project-lite",
"tokio", "tokio",
"tokio-rustls 0.23.2", "tokio-rustls 0.23.3",
"tungstenite", "tungstenite",
"webpki-roots 0.22.2", "webpki-roots 0.22.3",
] ]
[[package]] [[package]]
@ -365,7 +365,7 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"sha2 0.10.2", "sha2 0.10.2",
"subtle", "subtle",
"time 0.3.7", "time 0.3.9",
"version_check", "version_check",
] ]
@ -525,6 +525,17 @@ dependencies = [
"crypto-bigint", "crypto-bigint",
] ]
[[package]]
name = "derivative"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "deunicode" name = "deunicode"
version = "0.4.3" version = "0.4.3"
@ -607,9 +618,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.30" version = "0.8.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@ -867,9 +878,9 @@ dependencies = [
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.5" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d39cd93900197114fa1fcb7ae84ca742095eed9442088988ae74fa744e930e77" checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"js-sys", "js-sys",
@ -920,9 +931,9 @@ dependencies = [
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.12" version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62eeb471aa3e3c9197aa4bfeabfe02982f6dc96f750486c0bb0009ac58b26d2b" checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@ -933,7 +944,7 @@ dependencies = [
"indexmap", "indexmap",
"slab", "slab",
"tokio", "tokio",
"tokio-util 0.6.9", "tokio-util 0.7.1",
"tracing", "tracing",
] ]
@ -1045,9 +1056,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.17" version = "0.14.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "043f0e083e9901b6cc658a77d1eb86f4fc650bbb977a4337dd63192826aa85dd" checksum = "b26ae0a80afebe130861d90abf98e3814a4f28a4c6ffeb5ab8ebb2be311e0ef2"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@ -1077,7 +1088,7 @@ dependencies = [
"hyper", "hyper",
"rustls 0.20.4", "rustls 0.20.4",
"tokio", "tokio",
"tokio-rustls 0.23.2", "tokio-rustls 0.23.3",
] ]
[[package]] [[package]]
@ -1130,9 +1141,9 @@ dependencies = [
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "1.8.0" version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
dependencies = [ dependencies = [
"autocfg 1.1.0", "autocfg 1.1.0",
"hashbrown", "hashbrown",
@ -1206,9 +1217,9 @@ checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.56" version = "0.3.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a38fc24e30fd564ce974c02bf1d337caddff65be6cc4735a1f7eab22a7440f04" checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -1246,9 +1257,9 @@ checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.121" version = "0.2.122"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" checksum = "ec647867e2bf0772e28c8bcde4f0d19a9216916e890543b5a03ed8ef27b8f259"
[[package]] [[package]]
name = "libm" name = "libm"
@ -1258,18 +1269,19 @@ checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.6" version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53"
dependencies = [ dependencies = [
"autocfg 1.1.0",
"scopeguard", "scopeguard",
] ]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.14" version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@ -1436,9 +1448,9 @@ dependencies = [
[[package]] [[package]]
name = "native-tls" name = "native-tls"
version = "0.2.8" version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d" checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
@ -1596,7 +1608,7 @@ checksum = "80e47cfc4c0a1a519d9a025ebfbac3a2439d1b5cdf397d72dcb79b11d9920dab"
dependencies = [ dependencies = [
"base64", "base64",
"chrono", "chrono",
"getrandom 0.2.5", "getrandom 0.2.6",
"http", "http",
"rand 0.8.5", "rand 0.8.5",
"reqwest", "reqwest",
@ -1686,7 +1698,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58" checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [ dependencies = [
"lock_api", "lock_api",
"parking_lot_core 0.9.1", "parking_lot_core 0.9.2",
] ]
[[package]] [[package]]
@ -1705,9 +1717,9 @@ dependencies = [
[[package]] [[package]]
name = "parking_lot_core" name = "parking_lot_core"
version = "0.9.1" version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" checksum = "995f667a6c822200b0433ac218e05582f0e2efa1b922a3fd2fbaadc5f87bab37"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"libc", "libc",
@ -1727,9 +1739,9 @@ dependencies = [
[[package]] [[package]]
name = "paste" name = "paste"
version = "1.0.6" version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" checksum = "0c520e05135d6e763148b6426a837e239041653ba7becd2e538c076c738025fc"
[[package]] [[package]]
name = "pear" name = "pear"
@ -1889,16 +1901,17 @@ dependencies = [
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.24" version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
[[package]] [[package]]
name = "poise" name = "poise"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0fc5d548e32fc7e3c8ea490afe95db00ec17ec24" source = "git+https://github.com/kangalioo/poise?branch=develop#040003164dbb39cc0bad83b21a551dc2f8f2b059"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"derivative",
"futures-core", "futures-core",
"futures-util", "futures-util",
"log", "log",
@ -1912,7 +1925,7 @@ dependencies = [
[[package]] [[package]]
name = "poise_macros" name = "poise_macros"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/kangalioo/poise?branch=master#0fc5d548e32fc7e3c8ea490afe95db00ec17ec24" source = "git+https://github.com/kangalioo/poise?branch=develop#040003164dbb39cc0bad83b21a551dc2f8f2b059"
dependencies = [ dependencies = [
"darling", "darling",
"proc-macro2", "proc-macro2",
@ -1958,9 +1971,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.36" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -1980,9 +1993,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.16" version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57" checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]
@ -2046,7 +2059,7 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7"
dependencies = [ dependencies = [
"getrandom 0.2.5", "getrandom 0.2.6",
] ]
[[package]] [[package]]
@ -2060,9 +2073,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.11" version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c" checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -2202,13 +2215,13 @@ dependencies = [
"serde_urlencoded", "serde_urlencoded",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"tokio-rustls 0.23.2", "tokio-rustls 0.23.3",
"tokio-util 0.6.9", "tokio-util 0.6.9",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
"webpki-roots 0.22.2", "webpki-roots 0.22.3",
"winreg", "winreg",
] ]
@ -2277,10 +2290,10 @@ dependencies = [
"serde_json", "serde_json",
"state", "state",
"tempfile", "tempfile",
"time 0.3.7", "time 0.3.9",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tokio-util 0.7.0", "tokio-util 0.7.1",
"ubyte", "ubyte",
"version_check", "version_check",
"yansi", "yansi",
@ -2335,9 +2348,9 @@ dependencies = [
"smallvec", "smallvec",
"stable-pattern", "stable-pattern",
"state", "state",
"time 0.3.7", "time 0.3.9",
"tokio", "tokio",
"tokio-rustls 0.23.2", "tokio-rustls 0.23.3",
"uncased", "uncased",
] ]
@ -2557,25 +2570,27 @@ dependencies = [
[[package]] [[package]]
name = "serenity" name = "serenity"
version = "0.10.10" version = "0.10.10"
source = "git+https://github.com/serenity-rs/serenity?branch=next#56c40fc53cab1ebda43d1efc0fcd4ab37a73a3d2" source = "git+https://github.com/serenity-rs/serenity?branch=next#cf5585266e7ba502099da12bdaa91213741b1c59"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"async-tungstenite", "async-tungstenite",
"base64", "base64",
"bitflags", "bitflags",
"bytes", "bytes",
"cfg-if 1.0.0",
"chrono", "chrono",
"dashmap", "dashmap",
"flate2", "flate2",
"futures", "futures",
"mime", "mime",
"mime_guess", "mime_guess",
"parking_lot 0.11.2", "parking_lot 0.12.0",
"percent-encoding", "percent-encoding",
"reqwest", "reqwest",
"serde", "serde",
"serde-value", "serde-value",
"serde_json", "serde_json",
"time 0.3.9",
"tokio", "tokio",
"tracing", "tracing",
"typemap_rev", "typemap_rev",
@ -2607,6 +2622,17 @@ dependencies = [
"opaque-debug 0.3.0", "opaque-debug 0.3.0",
] ]
[[package]]
name = "sha-1"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f"
dependencies = [
"cfg-if 1.0.0",
"cpufeatures",
"digest 0.10.3",
]
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.9.9" version = "0.9.9"
@ -2657,9 +2683,9 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.5" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
[[package]] [[package]]
name = "slug" name = "slug"
@ -2852,9 +2878,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.89" version = "1.0.91"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54" checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2959,21 +2985,22 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.7" version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "004cbc98f30fa233c61a38bc77e96a9106e65c88f2d3bef182ae952027e5753d" checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd"
dependencies = [ dependencies = [
"itoa", "itoa",
"libc", "libc",
"num_threads", "num_threads",
"serde",
"time-macros", "time-macros",
] ]
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.3" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6" checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792"
[[package]] [[package]]
name = "tinyvec" name = "tinyvec"
@ -3044,9 +3071,9 @@ dependencies = [
[[package]] [[package]]
name = "tokio-rustls" name = "tokio-rustls"
version = "0.23.2" version = "0.23.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a27d5f2b839802bd8267fa19b0530f5a08b9c08cd417976be2a65d130fe1c11b" checksum = "4151fda0cf2798550ad0b34bcfc9b9dcc2a9d2471c895c68f3a8818e54f2389e"
dependencies = [ dependencies = [
"rustls 0.20.4", "rustls 0.20.4",
"tokio", "tokio",
@ -3080,16 +3107,16 @@ dependencies = [
[[package]] [[package]]
name = "tokio-util" name = "tokio-util"
version = "0.7.0" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64910e1b9c1901aaf5375561e35b9c057d95ff41a44ede043a03e09279eabaf1" checksum = "0edfdeb067411dba2044da6d1cb2df793dd35add7888d73c16e3381ded401764"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-core", "futures-core",
"futures-sink", "futures-sink",
"log",
"pin-project-lite", "pin-project-lite",
"tokio", "tokio",
"tracing",
] ]
[[package]] [[package]]
@ -3133,9 +3160,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.23" version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa31669fa42c09c34d94d8165dd2012e8ff3c66aca50f3bb226b68f216f2706c" checksum = "90442985ee2f57c9e1b548ee72ae842f4a9a20e3f417cc38dbc5dc684d9bb4ee"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"valuable", "valuable",
@ -3154,9 +3181,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing-subscriber" name = "tracing-subscriber"
version = "0.3.9" version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e0ab7bdc962035a87fba73f3acca9b8a8d0034c2e6f60b84aeaaddddc155dce" checksum = "b9df98b037d039d03400d9dd06b0f8ce05486b5f25e9a2d7d36196e142ebbc52"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"lazy_static", "lazy_static",
@ -3178,9 +3205,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642"
[[package]] [[package]]
name = "tungstenite" name = "tungstenite"
version = "0.16.0" version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ad3713a14ae247f22a728a0456a545df14acf3867f905adff84be99e23b3ad1" checksum = "d96a2dea40e7570482f28eb57afbe42d97551905da6a9400acc5c328d24004f5"
dependencies = [ dependencies = [
"base64", "base64",
"byteorder", "byteorder",
@ -3190,7 +3217,7 @@ dependencies = [
"log", "log",
"rand 0.8.5", "rand 0.8.5",
"rustls 0.20.4", "rustls 0.20.4",
"sha-1 0.9.8", "sha-1 0.10.0",
"thiserror", "thiserror",
"url", "url",
"utf-8", "utf-8",
@ -3420,9 +3447,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.79" version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -3430,9 +3457,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.79" version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b21c0df030f5a177f3cba22e9bc4322695ec43e7257d865302900290bcdedca" checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"lazy_static", "lazy_static",
@ -3445,9 +3472,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-futures" name = "wasm-bindgen-futures"
version = "0.4.29" version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb6ec270a31b1d3c7e266b999739109abce8b6c87e4b31fcfcd788b65267395" checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"js-sys", "js-sys",
@ -3457,9 +3484,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.79" version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f4203d69e40a52ee523b2529a773d5ffc1dc0071801c87b3d270b471b80ed01" checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5"
dependencies = [ dependencies = [
"quote", "quote",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
@ -3467,9 +3494,9 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.79" version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa8a30d46208db204854cadbb5d4baf5fcf8071ba5bf48190c3e59937962ebc" checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3480,15 +3507,15 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.79" version = "0.2.80"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d958d035c4438e28c70e4321a2911302f10135ce78a9c7834c0cab4123d06a2" checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.56" version = "0.3.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c060b319f29dd25724f09a2ba1418f142f539b2be99fbf4d2d5a8f7330afb8eb" checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -3525,9 +3552,9 @@ dependencies = [
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "0.22.2" version = "0.22.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552ceb903e957524388c4d3475725ff2c8b7960922063af6ce53c9a43da07449" checksum = "44d8de8415c823c8abd270ad483c6feeac771fad964890779f9a8cb24fbbc1bf"
dependencies = [ dependencies = [
"webpki 0.22.0", "webpki 0.22.0",
] ]
@ -3577,9 +3604,9 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" checksum = "5acdd78cb4ba54c0045ac14f62d8f94a03d10047904ae2a40afa1e99d8f70825"
dependencies = [ dependencies = [
"windows_aarch64_msvc", "windows_aarch64_msvc",
"windows_i686_gnu", "windows_i686_gnu",
@ -3590,33 +3617,33 @@ dependencies = [
[[package]] [[package]]
name = "windows_aarch64_msvc" name = "windows_aarch64_msvc"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
[[package]] [[package]]
name = "windows_i686_gnu" name = "windows_i686_gnu"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
[[package]] [[package]]
name = "windows_i686_msvc" name = "windows_i686_msvc"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
[[package]] [[package]]
name = "windows_x86_64_gnu" name = "windows_x86_64_gnu"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
[[package]] [[package]]
name = "windows_x86_64_msvc" name = "windows_x86_64_msvc"
version = "0.32.0" version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
[[package]] [[package]]
name = "winreg" name = "winreg"
@ -3639,9 +3666,9 @@ dependencies = [
[[package]] [[package]]
name = "yansi" name = "yansi"
version = "0.5.0" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
[[package]] [[package]]
name = "zeroize" name = "zeroize"

View File

@ -5,7 +5,7 @@ authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
poise = { git = "https://github.com/kangalioo/poise", branch = "master" } poise = { git = "https://github.com/kangalioo/poise", branch = "develop" }
dotenv = "0.15" dotenv = "0.15"
tokio = { version = "1", features = ["process", "full"] } tokio = { version = "1", features = ["process", "full"] }
reqwest = "0.11" reqwest = "0.11"

View File

@ -2,6 +2,7 @@
address = "0.0.0.0" address = "0.0.0.0"
port = 5000 port = 5000
template_dir = "web/templates" template_dir = "web/templates"
limits = { json = "10MiB" }
[debug] [debug]
secret_key = "tR8krio5FXTnnyIZNiJDXPondz0kI1v6X6BXZcBGIRY=" secret_key = "tR8krio5FXTnnyIZNiJDXPondz0kI1v6X6BXZcBGIRY="

View File

@ -2,19 +2,74 @@ use std::{collections::HashMap, env, sync::atomic::Ordering};
use log::{error, info, warn}; use log::{error, info, warn};
use poise::{ use poise::{
async_trait,
serenity::{model::interactions::Interaction, utils::shard_id}, serenity::{model::interactions::Interaction, utils::shard_id},
serenity_prelude as serenity, serenity_prelude as serenity,
}; };
use crate::{component_models::ComponentDataModel, Data, Error}; use crate::{component_models::ComponentDataModel, Data, Error, GuildId};
struct Handler;
#[async_trait]
impl serenity::EventHandler for Handler {
async fn guild_create(&self, ctx: serenity::Context, guild: serenity::Guild, is_new: bool) {
if is_new {
let guild_id = guild.id.as_u64().to_owned();
// todo
// sqlx::query!("INSERT INTO guilds (guild) VALUES (?)", guild_id)
// .execute(&data.database)
// .await
// .unwrap();
//if let Ok(token) = env::var("DISCORDBOTS_TOKEN") {
// let shard_count = ctx.cache.shard_count();
// let current_shard_id = shard_id(guild_id, shard_count);
// let guild_count = ctx
// .cache
// .guilds()
// .iter()
// .filter(|g| {
// shard_id(g.as_u64().to_owned(), shard_count) == current_shard_id
// })
// .count() as u64;
// let mut hm = HashMap::new();
// hm.insert("server_count", guild_count);
// hm.insert("shard_id", current_shard_id);
// hm.insert("shard_count", shard_count);
// let response = data
// .http
// .post(
// format!(
// "https://top.gg/api/bots/{}/stats",
// ctx.cache.current_user_id().as_u64()
// )
// .as_str(),
// )
// .header("Authorization", token)
// .json(&hm)
// .send()
// .await;
// if let Err(res) = response {
// println!("DiscordBots Response: {:?}", res);
// }
//}
}
}
}
pub async fn listener( pub async fn listener(
ctx: &serenity::Context, ctx: &serenity::Context,
event: &poise::Event<'_>, event: &serenity::Event,
data: &Data, data: &Data,
) -> Result<(), Error> { ) -> Result<(), Error> {
match event { match event {
poise::Event::CacheReady { .. } => { serenity::Event::Ready(_) => {
info!("Cache Ready! Preparing extra processes"); info!("Cache Ready! Preparing extra processes");
if data if data
@ -55,69 +110,22 @@ pub async fn listener(
} }
} }
} }
poise::Event::ChannelDelete { channel } => { serenity::Event::ChannelDelete(event) => {
sqlx::query!("DELETE FROM channels WHERE channel = ?", channel.id.as_u64()) sqlx::query!("DELETE FROM channels WHERE channel = ?", event.channel.id().0)
.execute(&data.database) .execute(&data.database)
.await .await
.unwrap(); .unwrap();
} }
poise::Event::GuildCreate { guild, is_new } => { serenity::Event::GuildDelete(event) => {
if *is_new { let _ = sqlx::query!("DELETE FROM guilds WHERE guild = ?", event.guild.id.0)
let guild_id = guild.id.as_u64().to_owned();
sqlx::query!("INSERT INTO guilds (guild) VALUES (?)", guild_id)
.execute(&data.database)
.await
.unwrap();
if let Ok(token) = env::var("DISCORDBOTS_TOKEN") {
let shard_count = ctx.cache.shard_count();
let current_shard_id = shard_id(guild_id, shard_count);
let guild_count = ctx
.cache
.guilds()
.iter()
.filter(|g| {
shard_id(g.as_u64().to_owned(), shard_count) == current_shard_id
})
.count() as u64;
let mut hm = HashMap::new();
hm.insert("server_count", guild_count);
hm.insert("shard_id", current_shard_id);
hm.insert("shard_count", shard_count);
let response = data
.http
.post(
format!(
"https://top.gg/api/bots/{}/stats",
ctx.cache.current_user_id().as_u64()
)
.as_str(),
)
.header("Authorization", token)
.json(&hm)
.send()
.await;
if let Err(res) = response {
println!("DiscordBots Response: {:?}", res);
}
}
}
}
poise::Event::GuildDelete { incomplete, .. } => {
let _ = sqlx::query!("DELETE FROM guilds WHERE guild = ?", incomplete.id.0)
.execute(&data.database) .execute(&data.database)
.await; .await;
} }
poise::Event::InteractionCreate { interaction } => match interaction { serenity::Event::InteractionCreate(event) => match &event.interaction {
Interaction::MessageComponent(component) => { Interaction::MessageComponent(component) => {
let component_model = ComponentDataModel::from_custom_id(&component.data.custom_id); let component_model = ComponentDataModel::from_custom_id(&component.data.custom_id);
component_model.act(ctx, data, component).await; component_model.act(ctx, data, &component).await;
} }
_ => {} _ => {}
}, },

View File

@ -12,7 +12,6 @@ use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, T
use rocket::{ use rocket::{
fs::FileServer, fs::FileServer,
serde::json::{json, Value as JsonValue}, serde::json::{json, Value as JsonValue},
shield::Shield,
tokio::sync::broadcast::Sender, tokio::sync::broadcast::Sender,
}; };
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
@ -51,6 +50,11 @@ async fn not_found() -> Template {
Template::render("errors/404", &map) Template::render("errors/404", &map)
} }
#[catch(413)]
async fn payload_too_large() -> JsonValue {
json!({"error": "Data too large.", "errors": ["Data too large."]})
}
#[catch(422)] #[catch(422)]
async fn unprocessable_entity() -> JsonValue { async fn unprocessable_entity() -> JsonValue {
json!({"error": "Invalid request.", "errors": ["Invalid request."]}) json!({"error": "Invalid request.", "errors": ["Invalid request."]})
@ -67,6 +71,13 @@ pub async fn initialize(
serenity_context: Context, serenity_context: Context,
db_pool: Pool<Database>, db_pool: Pool<Database>,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
info!("Checking environment variables...");
env::var("OAUTH2_CLIENT_ID").expect("`OAUTH2_CLIENT_ID' not supplied");
env::var("OAUTH2_CLIENT_SECRET").expect("`OAUTH2_CLIENT_SECRET' not supplied");
env::var("OAUTH2_DISCORD_CALLBACK").expect("`OAUTH2_DISCORD_CALLBACK' not supplied");
env::var("PATREON_GUILD_ID").expect("`PATREON_GUILD' not supplied");
info!("Done!");
let oauth2_client = BasicClient::new( let oauth2_client = BasicClient::new(
ClientId::new(env::var("OAUTH2_CLIENT_ID")?), ClientId::new(env::var("OAUTH2_CLIENT_ID")?),
Some(ClientSecret::new(env::var("OAUTH2_CLIENT_SECRET")?)), Some(ClientSecret::new(env::var("OAUTH2_CLIENT_SECRET")?)),
@ -86,7 +97,8 @@ pub async fn initialize(
forbidden, forbidden,
not_found, not_found,
internal_server_error, internal_server_error,
unprocessable_entity unprocessable_entity,
payload_too_large,
], ],
) )
.manage(oauth2_client) .manage(oauth2_client)
@ -129,6 +141,7 @@ pub async fn initialize(
routes::dashboard::guild::get_guild_roles, routes::dashboard::guild::get_guild_roles,
routes::dashboard::guild::get_reminder_templates, routes::dashboard::guild::get_reminder_templates,
routes::dashboard::guild::create_reminder_template, routes::dashboard::guild::create_reminder_template,
routes::dashboard::guild::delete_reminder_template,
routes::dashboard::guild::create_reminder, routes::dashboard::guild::create_reminder,
routes::dashboard::guild::get_reminders, routes::dashboard::guild::get_reminders,
routes::dashboard::guild::edit_reminder, routes::dashboard::guild::edit_reminder,

View File

@ -25,7 +25,7 @@ use crate::{
}, },
routes::dashboard::{ routes::dashboard::{
create_database_channel, generate_uid, name_default, template_name_default, DeleteReminder, create_database_channel, generate_uid, name_default, template_name_default, DeleteReminder,
PatchReminder, Reminder, ReminderTemplate, DeleteReminderTemplate, PatchReminder, Reminder, ReminderTemplate,
}, },
}; };
@ -59,6 +59,7 @@ pub async fn get_guild_channels(
channels.sort_by(|(_, c1), (_, c2)| c1.position.cmp(&c2.position)); channels.sort_by(|(_, c1), (_, c2)| c1.position.cmp(&c2.position));
// todo change to map
for (channel_id, channel) in channels { for (channel_id, channel) in channels {
let mut ch = ChannelInfo { let mut ch = ChannelInfo {
name: channel.name.to_string(), name: channel.name.to_string(),
@ -67,29 +68,6 @@ pub async fn get_guild_channels(
webhook_name: None, webhook_name: None,
}; };
if let Ok(webhook_details) = sqlx::query!(
"SELECT webhook_id, webhook_token FROM channels WHERE channel = ?",
channel.id.as_u64()
)
.fetch_one(pool.inner())
.await
{
if let (Some(webhook_id), Some(webhook_token)) =
(webhook_details.webhook_id, webhook_details.webhook_token)
{
let webhook_res =
ctx.http.get_webhook_with_token(webhook_id, &webhook_token).await;
if let Ok(webhook) = webhook_res {
ch.webhook_avatar = webhook.avatar.map(|a| {
format!("{}/{}/{}.webp?size=128", DISCORD_CDN, webhook_id, a)
});
ch.webhook_name = webhook.name;
}
}
}
channel_info.push(ch); channel_info.push(ch);
} }
@ -260,6 +238,34 @@ pub async fn create_reminder_template(
} }
} }
#[delete("/api/guild/<id>/templates", data = "<delete_reminder_template>")]
pub async fn delete_reminder_template(
id: u64,
delete_reminder_template: Json<DeleteReminderTemplate>,
cookies: &CookieJar<'_>,
ctx: &State<Context>,
pool: &State<Pool<MySql>>,
) -> JsonValue {
check_authorization!(cookies, ctx.inner(), id);
match sqlx::query!(
"DELETE FROM reminder_template WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?) AND id = ?",
id, delete_reminder_template.id
)
.fetch_all(pool.inner())
.await
{
Ok(_) => {
json!({})
}
Err(e) => {
warn!("Could not delete template from {}: {:?}", id, e);
json!({"error": "Could not delete template"})
}
}
}
#[post("/api/guild/<id>/reminders", data = "<reminder>")] #[post("/api/guild/<id>/reminders", data = "<reminder>")]
pub async fn create_reminder( pub async fn create_reminder(
id: u64, id: u64,

View File

@ -60,6 +60,11 @@ pub struct ReminderTemplate {
username: Option<String>, username: Option<String>,
} }
#[derive(Deserialize)]
pub struct DeleteReminderTemplate {
id: u32,
}
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct EmbedField { pub struct EmbedField {
title: String, title: String,
@ -69,6 +74,7 @@ pub struct EmbedField {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct Reminder { pub struct Reminder {
#[serde(with = "base64s")]
attachment: Option<Vec<u8>>, attachment: Option<Vec<u8>>,
attachment_name: Option<String>, attachment_name: Option<String>,
avatar: Option<String>, avatar: Option<String>,
@ -189,6 +195,29 @@ mod string {
} }
} }
mod base64s {
use serde::{de, Deserialize, Deserializer, Serializer};
pub fn serialize<S>(value: &Option<Vec<u8>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
if let Some(opt) = value {
serializer.collect_str(&base64::encode(opt))
} else {
serializer.serialize_none()
}
}
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
where
D: Deserializer<'de>,
{
let string = String::deserialize(deserializer)?;
Some(base64::decode(string).map_err(de::Error::custom)).transpose()
}
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct DeleteReminder { pub struct DeleteReminder {
uid: String, uid: String,
@ -199,6 +228,8 @@ async fn create_database_channel(
channel: ChannelId, channel: ChannelId,
pool: impl Executor<'_, Database = Database> + Copy, pool: impl Executor<'_, Database = Database> + Copy,
) -> Result<u32, crate::Error> { ) -> Result<u32, crate::Error> {
println!("{:?}", channel);
let row = let row =
sqlx::query!("SELECT webhook_token, webhook_id FROM channels WHERE channel = ?", channel.0) sqlx::query!("SELECT webhook_token, webhook_id FROM channels WHERE channel = ?", channel.0)
.fetch_one(pool) .fetch_one(pool)
@ -239,11 +270,7 @@ async fn create_database_channel(
webhook_id, webhook_id,
webhook_token, webhook_token,
channel channel
) VALUES ( ) VALUES (?, ?, ?)",
webhook_id = ?,
webhook_token = ?,
channel = ?
)",
webhook.id.0, webhook.id.0,
webhook.token, webhook.token,
channel.0 channel.0

View File

@ -34,7 +34,7 @@ div.reminderContent.is-collapsed .channel-field {
order: 1; order: 1;
} }
div.reminderContent.is-collapsed .columns { div.reminderContent.is-collapsed .reminder-topbar {
display: inline-flex; display: inline-flex;
margin-bottom: 0px; margin-bottom: 0px;
flex-grow: 1; flex-grow: 1;
@ -555,3 +555,11 @@ textarea, input {
.create-reminder { .create-reminder {
margin: 0 12px 12px 12px; margin: 0 12px 12px 12px;
} }
.button.is-success:not(.is-outlined) {
color: white;
}
.button.is-outlined.is-success {
background-color: white;
}

View File

@ -10,6 +10,7 @@ const $createReminder = document.querySelector("#reminderCreator");
const $createReminderBtn = $createReminder.querySelector("button#createReminder"); const $createReminderBtn = $createReminder.querySelector("button#createReminder");
const $createTemplateBtn = $createReminder.querySelector("button#createTemplate"); const $createTemplateBtn = $createReminder.querySelector("button#createTemplate");
const $loadTemplateBtn = document.querySelector("button#load-template"); const $loadTemplateBtn = document.querySelector("button#load-template");
const $deleteTemplateBtn = document.querySelector("button#delete-template");
const $templateSelect = document.querySelector("select#templateSelect"); const $templateSelect = document.querySelector("select#templateSelect");
let channels = []; let channels = [];
@ -172,7 +173,7 @@ async function fetch_reminders(guild_id) {
} }
async function serialize_reminder(node, mode) { async function serialize_reminder(node, mode) {
let interval, utc_time; let interval, utc_time, expiration_time;
if (mode !== "template") { if (mode !== "template") {
interval = get_interval(node); interval = get_interval(node);
@ -185,6 +186,15 @@ async function serialize_reminder(node, mode) {
} else { } else {
utc_time = utc_time.toFormat("yyyy-LL-dd'T'HH:mm:ss"); utc_time = utc_time.toFormat("yyyy-LL-dd'T'HH:mm:ss");
} }
expiration_time = luxon.DateTime.fromISO(
node.querySelector('input[name="time"]').value
).setZone("UTC");
if (expiration_time.invalid) {
return { error: "Expiration provided invalid." };
} else {
expiration_time = expiration_time.toFormat("yyyy-LL-dd'T'HH:mm:ss");
}
} }
let rgb_color = window.getComputedStyle( let rgb_color = window.getComputedStyle(
@ -253,7 +263,7 @@ async function serialize_reminder(node, mode) {
), ),
embed_title: node.querySelector('textarea[name="embed_title"]').value, embed_title: node.querySelector('textarea[name="embed_title"]').value,
embed_fields: fields, embed_fields: fields,
expires: null, expires: expiration_time,
interval_seconds: mode !== "template" ? interval.seconds : null, interval_seconds: mode !== "template" ? interval.seconds : null,
interval_months: mode !== "template" ? interval.months : null, interval_months: mode !== "template" ? interval.months : null,
name: node.querySelector('input[name="name"]').value, name: node.querySelector('input[name="name"]').value,
@ -314,6 +324,14 @@ function deserialize_reminder(reminder, frame, mode) {
zone: "UTC", zone: "UTC",
}).setZone(timezone); }).setZone(timezone);
timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss"); timeInput.value = localTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");
if (reminder['expires']) {
let expiresInput = frame.querySelector('input[name="time"]');
let expiresTime = luxon.DateTime.fromISO(reminder["expires"], {
zone: "UTC",
}).setZone(timezone);
expiresInput.value = expiresTime.toFormat("yyyy-LL-dd'T'HH:mm:ss");
}
} }
} }
@ -578,12 +596,6 @@ function set_channels(element) {
newOption.value = channel.id; newOption.value = channel.id;
newOption.textContent = channel.name; newOption.textContent = channel.name;
if (channel.webhook_avatar !== null) {
newOption.dataset["webhookAvatar"] = channel.webhook_avatar;
}
if (channel.webhook_name !== null) {
newOption.dataset["webhookName"] = channel.webhook_name;
}
element.appendChild(newOption); element.appendChild(newOption);
} }
@ -659,6 +671,10 @@ $createReminderBtn.addEventListener("click", async () => {
}); });
$createTemplateBtn.addEventListener("click", async () => { $createTemplateBtn.addEventListener("click", async () => {
$createTemplateBtn.querySelector("span.icon > i").classList = [
"fas fa-spinner fa-spin",
];
let reminder = await serialize_reminder($createReminder, "template"); let reminder = await serialize_reminder($createReminder, "template");
let guild = guildId(); let guild = guildId();
@ -700,6 +716,25 @@ $loadTemplateBtn.addEventListener("click", (ev) => {
); );
}); });
$deleteTemplateBtn.addEventListener("click", (ev) => {
fetch(`/dashboard/api/guild/${guildId()}/templates`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({id: parseInt($templateSelect.value)}),
})
.then((response) => response.json())
.then((data) => {
if (data.error) {
show_error(data.error)
} else {
$templateSelect.querySelector(`option[value="${$templateSelect.value}"]`).remove();
}
})
});
document.querySelectorAll("textarea.autoresize").forEach((element) => { document.querySelectorAll("textarea.autoresize").forEach((element) => {
element.addEventListener("input", () => { element.addEventListener("input", () => {
element.style.height = ""; element.style.height = "";

View File

@ -6,7 +6,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="yandex-verification" content="bb77b8681eb64a90"/> <meta name="yandex-verification" content="bb77b8681eb64a90"/>
<meta name="google-site-verification" content="7h7UVTeEe0AOzHiH3cFtsqMULYGN-zCZdMT_YCkW1Ho"/> <meta name="google-site-verification" content="7h7UVTeEe0AOzHiH3cFtsqMULYGN-zCZdMT_YCkW1Ho"/>
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src *; font-src fonts.gstatic.com 'self'"> <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src *; font-src fonts.gstatic.com 'self'"> -->
<!-- favicon --> <!-- favicon -->
<link rel="apple-touch-icon" sizes="180x180" <link rel="apple-touch-icon" sizes="180x180"

View File

@ -112,7 +112,7 @@
</article> </article>
</div> </div>
<div class="column settings"> <div class="column settings">
<div class="columns is-mobile"> <div class="columns is-mobile reminder-topbar">
<div class="column"> <div class="column">
<div class="field"> <div class="field">
<div class="control"> <div class="control">
@ -128,9 +128,11 @@
</div> </div>
</div> </div>
<div class="columns">
<div class="column">
<div class="field channel-field"> <div class="field channel-field">
<div class="collapses"> <div class="collapses">
<label class="label" for="channelOption">Channel</label> <label class="label" for="channelOption">Channel*</label>
</div> </div>
<div class="control has-icons-left"> <div class="control has-icons-left">
<div class="select"> <div class="select">
@ -141,20 +143,24 @@
<i class="fas fa-hashtag"></i> <i class="fas fa-hashtag"></i>
</div> </div>
</div> </div>
</div>
<div class="collapses"> </div>
<div class="column">
<div class="field"> <div class="field">
<div class="control"> <div class="control">
<label class="label"> <label class="label collapses">
Time Time*
<input class="input" type="datetime-local" step="1" name="time"> <input class="input" type="datetime-local" step="1" name="time">
</label> </label>
</div> </div>
</div> </div>
</div>
</div>
<div class="collapses">
<div class="field"> <div class="field">
<a class="intervalLabel"><label class="label">Interval <i class="fas fa-chevron-down"></i></label></a> <a class="intervalLabel"><label class="label">Interval <i class="fas fa-chevron-down"></i></label></a>
<div class="control intervalSelector"> <div class="control intervalSelector" style="min-width: 400px;" >
<div class="input interval-group"> <div class="input interval-group">
<div class="interval-group-left"> <div class="interval-group-left">
<label> <label>
@ -183,6 +189,15 @@
</div> </div>
</div> </div>
<div class="field">
<div class="control">
<label class="label">
Expiration
<input class="input" type="datetime-local" step="1" name="expiration">
</label>
</div>
</div>
<div class="columns"> <div class="columns">
<div class="column has-text-centered"> <div class="column has-text-centered">
<div class="is-boxed"> <div class="is-boxed">
@ -213,21 +228,20 @@
<span class="pad-left"></span> <span class="pad-left"></span>
{% if creating %} {% if creating %}
<button class="button is-outlined show-modal" data-modal="chooseTemplateModal"> <button class="button is-success" id="createReminder">
Load Template <span>Create Reminder</span> <span class="icon"><i class="fas fa-sparkles"></i></span>
</button> </button>
<button class="button is-success is-outlined" id="createTemplate"> <button class="button is-success is-outlined" id="createTemplate">
<span>Create Template</span> <span class="icon"><i class="fas fa-file-spreadsheet"></i></span> <span>Create Template</span> <span class="icon"><i class="fas fa-file-spreadsheet"></i></span>
</button> </button>
<button class="button is-success" id="createReminder"> <button class="button is-outlined show-modal is-pulled-right" data-modal="chooseTemplateModal">
<span>Create Reminder</span> <span class="icon"><i class="fas fa-sparkles"></i></span> Load Template
</button> </button>
{% else %} {% else %}
<button class="button is-primary save-btn"> <button class="button is-success save-btn">
<span>Save</span> <span class="icon"><i class="fas fa-save"></i></span> <span>Save</span> <span class="icon"><i class="fas fa-save"></i></span>
</button> </button>
<button class="button is-warning disable-enable"> <button class="button is-warning disable-enable">
<span class="is-sr-only">Text content filled by CSS</span>
</button> </button>
<button class="button is-danger delete-reminder"> <button class="button is-danger delete-reminder">
Delete Delete