From 909e28c82c17b9e07df6343052bd7bdb272c799c Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sun, 30 May 2021 14:58:25 -0400 Subject: [PATCH 1/7] Switch to GitHub Container registry Apparently the GitHub Packages Docker Registry is being replaced by the Container registry, which among other advantages allows anonymous access to public images, which seems useful. --- .github/workflows/ci.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8bb669..58d915e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,7 +88,7 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - name: Build docker container - run: docker build -t docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:branch . + run: docker build -t ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:branch . build_publish: name: Build and publish docker container runs-on: ubuntu-latest @@ -101,19 +101,19 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v2 - - name: Login - run: docker login docker.pkg.github.com -u bahlo -p "${{ secrets.GITHUB_TOKEN }}" + - name: Login to GitHub Container Registry + run: docker login ghcr.io -u ${GITHUB_ACTOR} -p "${{ secrets.GITHUB_TOKEN }}" - name: Build and publish docker latest if: github.ref == 'refs/heads/main' run: | - docker build -t docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:latest . - docker push docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:latest + docker build -t ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:latest . + docker push ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:latest - name: Build and publish docker tag if: startsWith(github.ref, 'refs/tags') run: | export TAG=$(echo "${{ github.ref }}" | sed 's/^refs\/tags\/v//g') - docker build -t docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:$TAG . - docker push docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:$TAG + docker build -t ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:$TAG . + docker push ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:$TAG create_release_upload_assets: name: Create release and upload assets runs-on: ubuntu-latest @@ -147,7 +147,7 @@ jobs: release_name: ${{ github.ref }} draft: false prerelease: false - body: See [CHANGELOG.md](https://github.com/bahlo/discord-retention-bot/blob/main/CHANGELOG.md) + body: See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/main/CHANGELOG.md) - name: Upload release asset uses: actions/upload-release-asset@v1 env: @@ -182,4 +182,4 @@ jobs: - name: Run cargo publish uses: actions-rs/cargo@v1 with: - command: publish \ No newline at end of file + command: publish From 3d6db24a3f3a0541abba9d108ced2f4240d458f7 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sun, 30 May 2021 15:06:24 -0400 Subject: [PATCH 2/7] Publish Docker image from "container" branch for packaging tests --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58d915e..2b3d267 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,7 +92,7 @@ jobs: build_publish: name: Build and publish docker container runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') # Run only on main or tags + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/container' || startsWith(github.ref, 'refs/tags') # Run only on main or tags needs: - clippy_check - test @@ -108,6 +108,11 @@ jobs: run: | docker build -t ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:latest . docker push ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:latest + - name: Build and publish docker testing + if: github.ref == 'refs/heads/container' + run: | + docker build -t ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:testing . + docker push ghcr.io/${GITHUB_REPOSITORY}/discord-retention-bot:testing - name: Build and publish docker tag if: startsWith(github.ref, 'refs/tags') run: | From ca874cd1ff0a2491a01e8e4e2562514823dd29e9 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 5 Jun 2021 13:22:11 -0400 Subject: [PATCH 3/7] Enable logging in unit tests --- src/bot.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bot.rs b/src/bot.rs index ff2b9b2..396b8f7 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -174,18 +174,28 @@ mod tests { utils::MessageBuilder, }; use std::{env, thread}; + use std::sync::Once; use tokio::runtime::Runtime; use super::*; const CHANNEL_NAME_CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789"; + static INIT: Once = Once::new(); + + fn setup_logger() { + INIT.call_once(|| { + env_logger::init(); + }); + } + macro_rules! integration_test { ($test_name:ident, $test_func:expr) => { #[test] #[ignore] fn $test_name() { dotenv().ok(); + setup_logger(); let discord_token = env::var("INTEGRATION_DISCORD_TOKEN") .expect("INTEGRATION_DISCORD_TOKEN is unset"); validate_token(&discord_token).expect("Token is invalid"); From af8917f141ce32111748a1ff494fc76335839575 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 5 Jun 2021 13:22:32 -0400 Subject: [PATCH 4/7] Update to newer serenity+tokio --- Cargo.lock | 374 +++++++++++++++++------------------------------------ Cargo.toml | 4 +- 2 files changed, 124 insertions(+), 254 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8683842..874ec7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "adler" version = "0.2.3" @@ -34,18 +36,18 @@ dependencies = [ [[package]] name = "async-tungstenite" -version = "0.9.3" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce503a5cb1e7450af7d211b86b84807791b251f335b2f43f1e26b85a416f315" +checksum = "f7cc5408453d37e2b1c6f01d8078af1da58b6cfa6a80fa2ede3bd2b9a6ada9c4" dependencies = [ "futures-io", "futures-util", "log", - "pin-project 1.0.2", - "tokio 0.2.23", + "pin-project", + "tokio 1.6.1", "tokio-rustls", "tungstenite", - "webpki-roots", + "webpki-roots 0.20.0", ] [[package]] @@ -56,7 +58,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -110,6 +112,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "bytes" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" + [[package]] name = "cc" version = "1.0.66" @@ -139,17 +147,7 @@ dependencies = [ "num-traits", "serde", "time", - "winapi 0.3.9", -] - -[[package]] -name = "console_error_panic_hook" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" -dependencies = [ - "cfg-if 0.1.10", - "wasm-bindgen", + "winapi", ] [[package]] @@ -190,7 +188,7 @@ dependencies = [ "serde_json", "serenity", "thiserror", - "tokio 0.2.23", + "tokio 1.6.1", "tokio-test", ] @@ -250,22 +248,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures" version = "0.3.8" @@ -354,7 +336,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project 1.0.2", + "pin-project", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -384,11 +366,11 @@ dependencies = [ [[package]] name = "h2" -version = "0.2.7" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" +checksum = "825343c4eef0b63f541f8903f395dc5beb362a979b5799a84062527ef1e37726" dependencies = [ - "bytes", + "bytes 1.0.1", "fnv", "futures-core", "futures-sink", @@ -396,10 +378,9 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 0.2.23", + "tokio 1.6.1", "tokio-util", "tracing", - "tracing-futures", ] [[package]] @@ -423,19 +404,20 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" dependencies = [ - "bytes", + "bytes 0.5.6", "fnv", "itoa", ] [[package]] name = "http-body" -version = "0.3.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ - "bytes", + "bytes 1.0.1", "http", + "pin-project-lite", ] [[package]] @@ -458,11 +440,11 @@ checksum = "3c1ad908cc71012b7bea4d0c53ba96a8cba9962f048fa68d143376143d863b7a" [[package]] name = "hyper" -version = "0.13.9" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" +checksum = "8bf09f61b52cfcf4c00de50df88ae423d6c02354e385a86341133b5338630ad1" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-channel", "futures-core", "futures-util", @@ -472,9 +454,9 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.2", + "pin-project", "socket2", - "tokio 0.2.23", + "tokio 1.6.1", "tower-service", "tracing", "want", @@ -482,16 +464,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.21.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37743cc83e8ee85eacfce90f2f4102030d9ff0a95244098d781e9bee4a90abb6" +checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ - "bytes", "futures-util", "hyper", "log", "rustls", - "tokio 0.2.23", + "tokio 1.6.1", "tokio-rustls", "webpki", ] @@ -523,16 +504,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19a8a95243d5a0398cae618ec29477c6e3cb631152be5c19481f80bc71559754" dependencies = [ - "bytes", -] - -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", + "bytes 0.5.6", ] [[package]] @@ -556,16 +528,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -574,9 +536,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" [[package]] name = "log" @@ -627,44 +589,33 @@ dependencies = [ [[package]] name = "mio" -version = "0.6.23" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" +checksum = "cf80d3e903b34e0bd7282b218398aec54e082c840d9baf8339e0080a0c542956" dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", "log", "miow", - "net2", - "slab", - "winapi 0.2.8", + "ntapi", + "winapi", ] [[package]] name = "miow" -version = "0.2.2" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", + "winapi", ] [[package]] -name = "net2" -version = "0.2.37" +name = "ntapi" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -686,6 +637,16 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "once_cell" version = "1.5.2" @@ -704,33 +665,13 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal 0.4.27", -] - [[package]] name = "pin-project" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" dependencies = [ - "pin-project-internal 1.0.2", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] @@ -744,12 +685,6 @@ dependencies = [ "syn", ] -[[package]] -name = "pin-project-lite" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b" - [[package]] name = "pin-project-lite" version = "0.2.0" @@ -782,9 +717,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038" dependencies = [ "unicode-xid", ] @@ -839,12 +774,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "regex" version = "1.4.2" @@ -865,12 +794,12 @@ checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" [[package]] name = "reqwest" -version = "0.10.9" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb15d6255c792356a0f578d8a645c677904dc02e862bebe2ecc18e0c01b9a0ce" +checksum = "2296f2fac53979e8ccbc4a1136b25dcefd37be9ed7e4a1f6b05a6029c84ff124" dependencies = [ "base64 0.13.0", - "bytes", + "bytes 1.0.1", "encoding_rs", "futures-core", "futures-util", @@ -885,19 +814,18 @@ dependencies = [ "mime", "mime_guess", "percent-encoding", - "pin-project-lite 0.2.0", + "pin-project-lite", "rustls", "serde", "serde_json", "serde_urlencoded", - "tokio 0.2.23", + "tokio 1.6.1", "tokio-rustls", "url", "wasm-bindgen", "wasm-bindgen-futures", - "wasm-bindgen-test", "web-sys", - "webpki-roots", + "webpki-roots 0.21.1", "winreg", ] @@ -913,16 +841,16 @@ dependencies = [ "spin", "untrusted", "web-sys", - "winapi 0.3.9", + "winapi", ] [[package]] name = "rustls" -version = "0.18.1" +version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d1126dcf58e93cee7d098dbda643b5f92ed724f1f6a63007c1116eed6700c81" +checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64 0.12.3", + "base64 0.13.0", "log", "ring", "sct", @@ -935,12 +863,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "sct" version = "0.6.0" @@ -996,24 +918,24 @@ dependencies = [ [[package]] name = "serenity" -version = "0.9.2" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "735cb8c0093fe7478801f77badf0395476eb24e12a68dc4a4aa83ee149b8724b" +checksum = "e7775b6c4a554e495372cfa5d0e70349c84c62415666cf80c1ea79bc447c78d9" dependencies = [ "async-trait", "async-tungstenite", "base64 0.13.0", "bitflags", - "bytes", + "bytes 1.0.1", "chrono", "flate2", "futures", + "percent-encoding", "reqwest", "serde", "serde_json", - "tokio 0.2.23", + "tokio 1.6.1", "tracing", - "tracing-futures", "typemap_rev", "url", ] @@ -1039,14 +961,12 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "socket2" -version = "0.3.17" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" +checksum = "9e3dfc207c526015c632472a77be09cf1b6e46866581aecae5cc38fb4235dea2" dependencies = [ - "cfg-if 1.0.0", "libc", - "redox_syscall", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1057,9 +977,9 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" [[package]] name = "syn" -version = "1.0.53" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8833e20724c24de12bbaba5ad230ea61c3eafb05b881c7c9d3cfe8638b187e68" +checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" dependencies = [ "proc-macro2", "quote", @@ -1112,7 +1032,7 @@ checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" dependencies = [ "libc", "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1132,39 +1052,37 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "0.2.23" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6d7ad61edd59bfcc7e80dababf0f4aed2e6d5e0ba1659356ae889752dfc12ff" +checksum = "a12a3eb39ee2c231be64487f1fcbe726c8f2514876a55480a5ab8559fc374252" dependencies = [ - "bytes", - "fnv", + "autocfg", "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio", - "pin-project-lite 0.1.11", + "pin-project-lite", "slab", - "tokio-macros", ] [[package]] name = "tokio" -version = "0.3.5" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12a3eb39ee2c231be64487f1fcbe726c8f2514876a55480a5ab8559fc374252" +checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975" dependencies = [ "autocfg", - "futures-core", - "pin-project-lite 0.2.0", - "slab", + "bytes 1.0.1", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "tokio-macros", ] [[package]] name = "tokio-macros" -version = "0.2.6" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" +checksum = "c49e3df43841dafb86046472506755d8501c5615673955f6aa17181125d13c37" dependencies = [ "proc-macro2", "quote", @@ -1173,13 +1091,12 @@ dependencies = [ [[package]] name = "tokio-rustls" -version = "0.14.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12831b255bcfa39dc0436b01e19fea231a37db570686c06ee72c423479f889a" +checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" dependencies = [ - "futures-core", "rustls", - "tokio 0.2.23", + "tokio 1.6.1", "webpki", ] @@ -1189,23 +1106,23 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edc5a2b13a713b9134debc9aa1265b0a1ccf6a81fa05af2ba26e4aee56cdf1a" dependencies = [ - "bytes", + "bytes 0.5.6", "futures-core", "tokio 0.3.5", ] [[package]] name = "tokio-util" -version = "0.3.1" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" +checksum = "1caa0b0c8d94a049db56b5acf8cba99dc0623aab1b26d5b5f5e2d945846b3592" dependencies = [ - "bytes", + "bytes 1.0.1", "futures-core", "futures-sink", "log", - "pin-project-lite 0.1.11", - "tokio 0.2.23", + "pin-project-lite", + "tokio 1.6.1", ] [[package]] @@ -1216,22 +1133,22 @@ checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] name = "tracing" -version = "0.1.22" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" +checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.0", + "pin-project-lite", "tracing-attributes", "tracing-core", ] [[package]] name = "tracing-attributes" -version = "0.1.11" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80e0ccfc3378da0cce270c946b676a376943f5cd16aeba64568e7939806f4ada" +checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" dependencies = [ "proc-macro2", "quote", @@ -1240,23 +1157,13 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" +checksum = "a9ff14f98b1a4b289c6248a023c1c2fa1491062964e9fed67ab29c4e4da4a052" dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" -dependencies = [ - "pin-project 0.4.27", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -1271,7 +1178,7 @@ checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" dependencies = [ "base64 0.12.3", "byteorder", - "bytes", + "bytes 0.5.6", "http", "httparse", "input_buffer", @@ -1447,30 +1354,6 @@ version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" -[[package]] -name = "wasm-bindgen-test" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0355fa0c1f9b792a09b6dcb6a8be24d51e71e6d74972f9eb4a44c4c004d24a25" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27e07b46b98024c2ba2f9e83a10c2ef0515f057f2da299c1762a2017de80438b" -dependencies = [ - "proc-macro2", - "quote", -] - [[package]] name = "web-sys" version = "0.3.46" @@ -1501,10 +1384,13 @@ dependencies = [ ] [[package]] -name = "winapi" -version = "0.2.8" +name = "webpki-roots" +version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" +dependencies = [ + "webpki", +] [[package]] name = "winapi" @@ -1516,12 +1402,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1534,7 +1414,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1549,15 +1429,5 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0120db82e8a1e0b9fb3345a539c478767c0048d842860994d96113d5b667bd69" dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 0881321..1d70a89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ categories = ["command-line-utilities"] dotenv = "0.15.0" log = "0.4.11" env_logger = "0.8.2" -serenity = { version = "0.9", default-features = false, features = ["builder", "client", "gateway", "http", "model", "rustls_backend"] } -tokio = { version = "0.2", features = ["macros"] } +serenity = { version = "0.10", default-features = false, features = ["builder", "client", "gateway", "http", "model", "rustls_backend"] } +tokio = { version = "1.6", features = ["macros", "time", "rt-multi-thread"] } chrono = "0.4" anyhow = "1.0" thiserror = "1.0" From 93250a89d678ab0ee706372893246b7b98b7fa50 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 5 Jun 2021 13:52:02 -0400 Subject: [PATCH 5/7] Add note about needing to connect to a gateway to run tests --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 103d865..83d3be6 100644 --- a/README.md +++ b/README.md @@ -113,3 +113,10 @@ To run integration tests you need to create a bot (see * Read Message History Export the bot token to `INTEGRATION_DISCORD_TOKEN` and run `cargo test -- --ignored` to run the integration tests. + +Your bot will need to connect (just once, not each time you run the tests) to a +Discord gateway in order to [send the +messages](https://discord.com/developers/docs/resources/channel#create-message) +that the test deletes (otherwise, you'll see a 40001 Unauthorized JSON error). +You can do this by just making a quick script that calls +[serenity::Client::start](https://docs.rs/serenity/0.10.7/serenity/client/struct.Client.html#method.start). From b23d4d42f102f7c7ecadcdb82180eb4e0ac3a010 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 5 Jun 2021 17:20:16 -0400 Subject: [PATCH 6/7] Set sleep duration to be a tenth of the minimum retention interval When the minimum retention interval supported is an hour, it seems a little silly to check for messages every minute. When the minimum retention interval configured is a month, it seems extra silly. 10% is probably a reasonable error margin in retention interval, and probably means significantly less time processing. --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d79d80e..149501a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,10 @@ async fn main() -> Result<()> { .context("CHANNEL_RETENTION is unset") .and_then(config::parse_channel_retention) .context("Could not parse channel retention")?; + let def_retention = Duration::weeks(50); + let min_retention = channel_retention.values().min() + .unwrap_or(&def_retention); + info!("Minimum retention interval {} hours", min_retention.num_hours()); let delete_pinned = env::var("DELETE_PINNED") .map(|val| val == "true") .unwrap_or(false); @@ -28,7 +32,8 @@ async fn main() -> Result<()> { let client = Http::new_with_token(&discord_token); - let mut interval = time::interval(Duration::minutes(1).to_std()?); + let tick_duration = Duration::minutes(min_retention.num_minutes() / 10); + let mut interval = time::interval(tick_duration.to_std()?); interval.tick().await; // the first tick completes immediately loop { From b43df4c09b800e9a76196511046180b5c6282aa0 Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 5 Jun 2021 17:26:27 -0400 Subject: [PATCH 7/7] Fix more compiler warnings --- src/bot.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index 396b8f7..1350d1a 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -17,14 +17,14 @@ pub async fn run( channel_retention: &HashMap, delete_pinned: bool, ) -> Result<()> { - let guilds = get_all_guilds(&client).await?; + let guilds = get_all_guilds(client).await?; let mut guild_futures = FuturesUnordered::new(); for guild in guilds { guild_futures.push(process_guild( - &client, + client, guild, - &channel_retention, + channel_retention, delete_pinned, )); }