play command working sort of

This commit is contained in:
jude-lafitteIII 2020-04-26 23:12:31 +01:00
parent 8347f340d5
commit 7653fbcfeb
5 changed files with 411 additions and 359 deletions

2
.env Normal file
View File

@ -0,0 +1,2 @@
DATABASE_URL=mysql://jude@localhost:soundfx
DISCORD_TOKEN=NjAzMjc3NDk1NDA3NjA3ODA4.XVCxDw.tdghSFwhpet0RrXjF8PAbXscR7c

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target
.env

591
Cargo.lock generated
View File

@ -6,45 +6,24 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2"
[[package]]
name = "arc-swap"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62"
[[package]]
name = "async-native-tls"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9e7a929bd34c68a82d58a4de7f86fffdaf97fb2af850162a7bb19dd7269b33"
dependencies = [
"async-std",
"native-tls",
"thiserror",
"tokio",
"url",
]
[[package]]
name = "async-std"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "538ecb01eb64eecd772087e5b6f7540cbc917f047727339a472dafed2185b267"
dependencies = [
"async-task",
"broadcaster",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"futures-core",
"futures-io",
"futures-timer",
"kv-log-macro",
"log",
"memchr",
"mio",
"mio-uds",
"num_cpus",
"once_cell",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "async-stream"
version = "0.2.1"
@ -67,13 +46,60 @@ dependencies = [
]
[[package]]
name = "async-task"
version = "1.3.1"
name = "async-tls"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ac2c016b079e771204030951c366db398864f5026f84a44dafb0ff20f02085d"
checksum = "6ce6977f57fa68da77ffe5542950d47e9c23d65f5bc7cb0a9f8700996913eec7"
dependencies = [
"libc",
"winapi 0.3.8",
"futures",
"rustls 0.16.0",
"webpki",
"webpki-roots 0.17.0",
]
[[package]]
name = "async-trait"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da71fef07bc806586090247e971229289f64c210a278ee5ae419314eb386b31d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "async-tungstenite"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4187bb446c8ecb8849f17cef7553db8bdb09e482e806257130189958fb42dca7"
dependencies = [
"async-tls",
"futures-io",
"futures-util",
"log",
"pin-project",
"tokio",
"tungstenite",
]
[[package]]
name = "audiopus"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3743519567e9135cf6f9f1a509851cb0c8e4cb9d66feb286668afb1923bec458"
dependencies = [
"audiopus_sys",
]
[[package]]
name = "audiopus_sys"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cabfa29cd59a7bf6fbb12b6a663dc26d30378b7303c67b803abf72a36dfc1223"
dependencies = [
"log",
"pkg-config",
]
[[package]]
@ -97,6 +123,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
[[package]]
name = "base64"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d5ca2cd0adc3f48f9e9ea5a6bbdf9ccc0bfade884847e484d452414c7ccffb3"
[[package]]
name = "bitflags"
version = "1.2.1"
@ -124,20 +156,6 @@ dependencies = [
"byte-tools",
]
[[package]]
name = "broadcaster"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9c972e21e0d055a36cf73e4daae870941fe7a8abcd5ac3396aab9e4c126bd87"
dependencies = [
"futures-channel",
"futures-core",
"futures-sink",
"futures-util",
"parking_lot 0.10.2",
"slab",
]
[[package]]
name = "bumpalo"
version = "3.2.1"
@ -156,16 +174,6 @@ version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "bytes"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c"
dependencies = [
"byteorder",
"iovec",
]
[[package]]
name = "bytes"
version = "0.5.4"
@ -196,21 +204,11 @@ dependencies = [
"time",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
"bitflags",
]
[[package]]
name = "command_attr"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c27d6155f93d880b6379d93ddc9b2417b3b69b715360c5f25525e4576338a381"
dependencies = [
"futures",
"proc-macro2",
"quote",
"syn",
@ -241,42 +239,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crossbeam-channel"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cced8691919c02aac3cb0a1bc2e9b73d89e832bf9a06fc579d4e71b68a2da061"
dependencies = [
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-deque"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
"maybe-uninit",
]
[[package]]
name = "crossbeam-epoch"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"lazy_static",
"maybe-uninit",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-queue"
version = "0.2.1"
@ -343,6 +305,18 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "filetime"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f59efc38004c988e4201d11d263b8171f49a2e7ec0bdbb71773433f271504a5e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]]
name = "flate2"
version = "1.0.14"
@ -464,12 +438,6 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27"
[[package]]
name = "futures-timer"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6"
[[package]]
name = "futures-util"
version = "0.3.4"
@ -515,12 +483,12 @@ version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "377038bf3c89d18d6ca1431e7a5027194fbd724ca10592b9487ede5e8e144f42"
dependencies = [
"bytes 0.5.4",
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http 0.2.1",
"http",
"indexmap",
"log",
"slab",
@ -543,24 +511,13 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
[[package]]
name = "http"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0"
dependencies = [
"bytes 0.4.12",
"fnv",
"itoa",
]
[[package]]
name = "http"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9"
dependencies = [
"bytes 0.5.4",
"bytes",
"fnv",
"itoa",
]
@ -571,8 +528,8 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b"
dependencies = [
"bytes 0.5.4",
"http 0.2.1",
"bytes",
"http",
]
[[package]]
@ -587,12 +544,12 @@ version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed6081100e960d9d74734659ffc9cc91daf1c0fc7aceb8eaa94ee1a3f5046f2e"
dependencies = [
"bytes 0.5.4",
"bytes",
"futures-channel",
"futures-core",
"futures-util",
"h2",
"http 0.2.1",
"http",
"http-body",
"httparse",
"itoa",
@ -611,7 +568,7 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac965ea399ec3a25ac7d13b8affd4b8f39325cca00858ddf5eb29b79e6b14b08"
dependencies = [
"bytes 0.5.4",
"bytes",
"ct-logs",
"futures-util",
"hyper",
@ -645,11 +602,11 @@ dependencies = [
[[package]]
name = "input_buffer"
version = "0.2.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e1b822cc844905551931d6f81608ed5f50a79c1078a4e2b4d42dbc7c1eedfbf"
checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754"
dependencies = [
"bytes 0.4.12",
"bytes",
]
[[package]]
@ -686,15 +643,6 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "kv-log-macro"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c54d9f465d530a752e6ebdc217e081a7a614b48cb200f6f0aee21ba6bc9aabb"
dependencies = [
"log",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -708,12 +656,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0"
[[package]]
name = "lock_api"
version = "0.3.4"
name = "libflate"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
checksum = "d9135df43b1f5d0e333385cb6e7897ecd1a43d7d11b91ac003f4d2c2d2401fdd"
dependencies = [
"scopeguard",
"adler32",
"crc32fast",
"rle-decode-fast",
"take_mut",
]
[[package]]
name = "libsodium-sys"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c344ff12b90ef8fa1f0fffacd348c1fd041db331841fec9eab23fdb991f5e73"
dependencies = [
"cc",
"libc",
"libflate",
"pkg-config",
"tar",
"vcpkg",
]
[[package]]
@ -731,27 +696,12 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "memoffset"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8"
dependencies = [
"autocfg",
]
[[package]]
name = "mime"
version = "0.3.16"
@ -790,12 +740,24 @@ dependencies = [
"kernel32-sys",
"libc",
"log",
"miow",
"miow 0.2.1",
"net2",
"slab",
"winapi 0.2.8",
]
[[package]]
name = "mio-named-pipes"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f5e374eff525ce1c5b7687c4cef63943e7686524a387933ad27ca7ec43779cb3"
dependencies = [
"log",
"mio",
"miow 0.3.3",
"winapi 0.3.8",
]
[[package]]
name = "mio-uds"
version = "0.6.7"
@ -819,6 +781,16 @@ dependencies = [
"ws2_32-sys",
]
[[package]]
name = "miow"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "396aa0f2003d7df8395cb93e09871561ccc3e785f0acb369170e8cc74ddf9226"
dependencies = [
"socket2",
"winapi 0.3.8",
]
[[package]]
name = "native-tls"
version = "0.2.4"
@ -848,6 +820,17 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "num-bigint"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.42"
@ -877,12 +860,6 @@ dependencies = [
"libc",
]
[[package]]
name = "once_cell"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c601810575c99596d4afc46f78a678c80105117c379eb3650cf99b8a21ce5b"
[[package]]
name = "opaque-debug"
version = "0.2.3"
@ -922,56 +899,6 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252"
dependencies = [
"lock_api",
"parking_lot_core 0.6.2",
"rustc_version",
]
[[package]]
name = "parking_lot"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
dependencies = [
"lock_api",
"parking_lot_core 0.7.1",
]
[[package]]
name = "parking_lot_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b"
dependencies = [
"cfg-if",
"cloudabi",
"libc",
"redox_syscall",
"rustc_version",
"smallvec 0.6.13",
"winapi 0.3.8",
]
[[package]]
name = "parking_lot_core"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e136c1904604defe99ce5fd71a28d473fa60a12255d511aa78a9ddf11237aeb"
dependencies = [
"cfg-if",
"cloudabi",
"libc",
"redox_syscall",
"smallvec 1.3.0",
"winapi 0.3.8",
]
[[package]]
name = "percent-encoding"
version = "2.1.0"
@ -1115,11 +1042,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b81e49ddec5109a9dcfc5f2a317ff53377c915e9ae9d4f2fb50914b85614e2"
dependencies = [
"base64 0.11.0",
"bytes 0.5.4",
"bytes",
"encoding_rs",
"futures-core",
"futures-util",
"http 0.2.1",
"http",
"http-body",
"hyper",
"hyper-rustls",
@ -1141,7 +1068,7 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"webpki-roots",
"webpki-roots 0.18.0",
"winreg",
]
@ -1161,13 +1088,10 @@ dependencies = [
]
[[package]]
name = "rustc_version"
version = "0.2.3"
name = "rle-decode-fast"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac"
[[package]]
name = "rustls"
@ -1223,12 +1147,6 @@ dependencies = [
"winapi 0.3.8",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "sct"
version = "0.6.0"
@ -1262,21 +1180,6 @@ dependencies = [
"libc",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "1.0.106"
@ -1322,29 +1225,33 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d314db361ec202fd5228a7e718dec877461093fcbdb492d52cb754ddc51adb9f"
version = "0.8.4"
dependencies = [
"async-tls",
"async-trait",
"async-tungstenite",
"audiopus",
"base64 0.11.0",
"bitflags",
"byteorder",
"bytes",
"chrono",
"command_attr",
"flate2",
"futures",
"log",
"parking_lot 0.9.0",
"rand",
"reqwest",
"rustls 0.16.0",
"serde",
"serde_json",
"sodiumoxide",
"static_assertions",
"threadpool",
"tungstenite",
"typemap",
"tokio",
"url",
"uwl",
"webpki",
"webpki-roots",
"webpki-roots 0.19.0",
]
[[package]]
@ -1359,27 +1266,62 @@ dependencies = [
"opaque-debug",
]
[[package]]
name = "sha2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
dependencies = [
"block-buffer",
"digest",
"fake-simd",
"opaque-debug",
]
[[package]]
name = "signal-hook-registry"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94f478ede9f64724c5d173d7bb56099ec3e2d9fc2774aac65d34b8b890405f41"
dependencies = [
"arc-swap",
"libc",
]
[[package]]
name = "slab"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
[[package]]
name = "smallvec"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6"
dependencies = [
"maybe-uninit",
]
[[package]]
name = "smallvec"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05720e22615919e4734f6a99ceae50d00226c3c5aca406e102ebc33298214e0a"
[[package]]
name = "socket2"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi 0.3.8",
]
[[package]]
name = "sodiumoxide"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "585232e78a4fc18133eef9946d3080befdf68b906c51b621531c37e91787fa2b"
dependencies = [
"libc",
"libsodium-sys",
]
[[package]]
name = "soundfx-rs"
version = "0.1.0"
@ -1387,6 +1329,7 @@ dependencies = [
"dotenv",
"serenity",
"sqlx",
"tokio",
]
[[package]]
@ -1412,20 +1355,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673fb6f30bdc14b7812a5ae22d7cc1e8e3d1debd5384eedbdf745827e9721cf3"
dependencies = [
"async-native-tls",
"async-std",
"async-stream",
"base64 0.12.0",
"bitflags",
"byteorder",
"crossbeam-queue",
"crossbeam-utils",
"digest",
"futures-channel",
"futures-core",
"futures-util",
"generic-array",
"hex",
"libc",
"log",
"memchr",
"num-bigint",
"percent-encoding",
"rand",
"sha-1",
"sha2",
"tokio",
"url",
]
@ -1436,7 +1385,6 @@ version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de981547a9e8c15336b30079ca040ca252aa91c071e05298d699981d6dec041"
dependencies = [
"async-std",
"dotenv",
"futures",
"lazy_static",
@ -1465,6 +1413,24 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "take_mut"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60"
[[package]]
name = "tar"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3"
dependencies = [
"filetime",
"libc",
"redox_syscall",
"xattr",
]
[[package]]
name = "tempfile"
version = "3.1.0"
@ -1499,15 +1465,6 @@ dependencies = [
"syn",
]
[[package]]
name = "threadpool"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865"
dependencies = [
"num_cpus",
]
[[package]]
name = "time"
version = "0.1.42"
@ -1521,20 +1478,37 @@ dependencies = [
[[package]]
name = "tokio"
version = "0.2.18"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ef16d072d2b6dc8b4a56c70f5c5ced1a37752116f8e7c1e80c659aa7cb6713"
checksum = "7d9c43f1bb96970e153bcbae39a65e249ccb942bd9d36dbdf086024920417c9c"
dependencies = [
"bytes 0.5.4",
"bytes",
"fnv",
"futures-core",
"iovec",
"lazy_static",
"libc",
"memchr",
"mio",
"mio-named-pipes",
"mio-uds",
"num_cpus",
"pin-project-lite",
"signal-hook-registry",
"slab",
"tokio-macros",
"winapi 0.3.8",
]
[[package]]
name = "tokio-macros"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1555,7 +1529,7 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499"
dependencies = [
"bytes 0.5.4",
"bytes",
"futures-core",
"futures-sink",
"log",
@ -1569,12 +1543,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
[[package]]
name = "traitobject"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
[[package]]
name = "try-lock"
version = "0.2.2"
@ -1583,14 +1551,14 @@ checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
[[package]]
name = "tungstenite"
version = "0.9.2"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0c2bd5aeb7dcd2bb32e472c8872759308495e5eccc942e929a513cd8d36110"
checksum = "cfea31758bf674f990918962e8e5f07071a3161bd7c4138ed23e416e1ac4264e"
dependencies = [
"base64 0.11.0",
"byteorder",
"bytes 0.4.12",
"http 0.1.21",
"bytes",
"http",
"httparse",
"input_buffer",
"log",
@ -1600,15 +1568,6 @@ dependencies = [
"utf-8",
]
[[package]]
name = "typemap"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6"
dependencies = [
"unsafe-any",
]
[[package]]
name = "typenum"
version = "1.11.2"
@ -1639,7 +1598,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4"
dependencies = [
"smallvec 1.3.0",
"smallvec",
]
[[package]]
@ -1648,15 +1607,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
[[package]]
name = "unsafe-any"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f"
dependencies = [
"traitobject",
]
[[package]]
name = "untrusted"
version = "0.7.0"
@ -1802,6 +1752,15 @@ dependencies = [
"untrusted",
]
[[package]]
name = "webpki-roots"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b"
dependencies = [
"webpki",
]
[[package]]
name = "webpki-roots"
version = "0.18.0"
@ -1811,6 +1770,15 @@ dependencies = [
"webpki",
]
[[package]]
name = "webpki-roots"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8eff4b7516a57307f9349c64bf34caa34b940b66fed4b2fb3136cb7386e5739"
dependencies = [
"webpki",
]
[[package]]
name = "winapi"
version = "0.2.8"
@ -1863,3 +1831,12 @@ dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "xattr"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c"
dependencies = [
"libc",
]

View File

@ -5,6 +5,7 @@ authors = ["jude-lafitteIII <judewrs@gmail.com>"]
edition = "2018"
[dependencies]
serenity = "0.8"
sqlx = {version = "0.3", features = ["runtime-tokio", "macros"]}
serenity = {path = "/home/jude/serenity", features = ["voice"]}
sqlx = {version = "0.3", default-features = false, features = ["runtime-tokio", "macros", "mysql"]}
dotenv = "0.15"
tokio = {version = "0.2.19", features = ["fs"]}

View File

@ -1,26 +1,43 @@
use serenity::{
client::{
Client, Context
bridge::{
gateway::GatewayIntents,
voice::ClientVoiceManager,
},
Client, Context,
},
framework::standard::{
Args, StandardFramework
Args, CommandResult, StandardFramework,
macros::{
command, group,
}
},
model::{
channel::Message
},
prelude::{
EventHandler, TypeMapKey, Mutex
}
prelude::*,
voice::ffmpeg,
};
use sqlx::{
Pool,
mysql::MySqlPool
mysql::{
MySqlPool,
MySqlConnection,
}
};
use dotenv::dotenv;
use std::{env, sync::Arc};
use tokio::{
fs::File,
};
use std::{
env,
path::Path,
sync::Arc,
};
struct SQLPool;
@ -35,7 +52,7 @@ impl TypeMapKey for VoiceManager {
}
#[group]
#[commands()]
#[commands(play)]
struct General;
struct Sound {
@ -47,23 +64,28 @@ struct Sound {
// create event handler for bot
struct Handler;
#[serenity::async_trait]
impl EventHandler for Handler {}
// entry point
#[tokio::main]
fn main() {
dotenv();
async fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv()?;
let framework = StandardFramework::new()
.configure(|c| c.prefix("?"))
.group(&GENERAL_GROUP);
let mut client = Client::new_with_framework(&env::var("DISCORD_TOKEN").expect("Missing token from environment"), Handler, framework)
.await
.expect("Error occurred creating client");
let mut client = Client::new_with_extras(
&env::var("DISCORD_TOKEN").expect("Missing token from environment"),
|extras| { extras
.framework(framework)
.event_handler(Handler)
.intents(GatewayIntents::GUILD_VOICE_STATES | GatewayIntents::GUILD_MESSAGES | GatewayIntents::GUILDS)
}).await.expect("Error occurred creating client");
{
let pool = MySqlPool::new(env::var("DATABASE_URL"));
let pool = MySqlPool::new(&env::var("DATABASE_URL").expect("No database URL provided")).await.unwrap();
let mut data = client.data.write().await;
data.insert::<SQLPool>(pool);
@ -71,77 +93,126 @@ fn main() {
data.insert::<VoiceManager>(Arc::clone(&client.voice_manager));
}
let _ = client.start().await.map_err(|reason| println!("Failed to start client: {:?}", reason));
client.start().await?;
Ok(())
}
async fn search_for_sound(query: String, db_connector: &MySqlConnection) -> Result<Sound, Box<dyn std::error::Error>> {
async fn search_for_sound(query: &str, db_pool: MySqlPool) -> Result<Sound, Box<dyn std::error::Error>> {
if query.to_lowercase().starts_with("id:") {
let id = query[3..].parse::<u32>()?;
let sound = sqlx::query!(
let sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT name, src
SELECT id, name, src
FROM sounds
WHERE id = ?
LIMIT 1
",
id
)
.fetch_one(&db_connector)
.fetch_one(&db_pool)
.await?;
Ok(Sound {
name: sound.name,
id,
src: sound.src,
})
Ok(sound)
}
else {
let name = query;
let sound = sqlx::query!(
let sound = sqlx::query_as_unchecked!(
Sound,
"
SELECT id, src
SELECT id, name, src
FROM sounds
ORDER BY rand()
WHERE name = ?
ORDER BY rand()
LIMIT 1
",
name
)
.fetch_one(&db_connector)
.fetch_one(&db_pool)
.await?;
Ok(Sound {
name,
id: sound.id,
src: sound.src,
})
Ok(sound)
}
}
async fn store_sound_source(sound: &Sound) -> Result<String, Box<dyn std::error::Error>> {
let caching_location = env::var("CACHING_LOCATION").unwrap_or(String::from("/tmp"));
let path_name = format!("{}/sound-{}", caching_location, sound.id);
let path = Path::new(&path_name);
if !path.exists() {
use tokio::prelude::*;
let mut file = File::create(&path).await?;
file.write_all(sound.src.as_ref()).await?;
}
Ok(path_name)
}
#[command]
async fn play(ctx: &mut Context, msg: &Message, args: Args) {
let search_term = args.collect().join(" ");
async fn play(ctx: &mut Context, msg: &Message, args: Args) -> CommandResult {
let guild = match msg.guild(&ctx.cache).await {
Some(guild) => guild,
let pool_lock = ctx.data.read().await
.get::<SQLPool>().expect("Could not get SQL Pool out of data");
None => {
return Ok(());
}
};
let mut pool = pool_lock.lock().await;
let guild_id = guild.read().await.id;
let sound_res = search_for_sound(search_term, pool).await;
let channel_to_join = guild.read().await
.voice_states.get(&msg.author.id)
.and_then(|voice_state| voice_state.channel_id);
match sound_res {
Ok(sound) => {
let source = sound.src;
match channel_to_join {
Some(user_channel) => {
let search_term = args.rest();
let pool = ctx.data.read().await
.get::<SQLPool>().cloned().expect("Could not get SQLPool from data");
let sound = search_for_sound(search_term, pool).await?;
let fp = store_sound_source(&sound).await?;
let voice_manager_lock = ctx.data.read().await
.get::<VoiceManager>().cloned().expect("Could not get VoiceManager from data");
let mut voice_manager = voice_manager_lock.lock().await;
match voice_manager.get_mut(guild_id) {
Some(handler) => {
// play sound
handler.play(ffmpeg(fp).await?);
}
Err(reason) => {
None => {
// try & join a voice channel
match voice_manager.join(guild_id, user_channel) {
Some(handler) => {
handler.play(ffmpeg(fp).await?);
}
None => {
msg.channel_id.say(&ctx, "Failed to join channel").await?;
}
};
}
}
}
None => {
msg.channel_id.say(&ctx, "You are not in a voice chat!").await?;
}
}
Ok(())
}