From 2ae2b978f3fad7a58cb129333b36a210bb200488 Mon Sep 17 00:00:00 2001 From: seth Date: Thu, 19 Dec 2024 16:26:18 -0500 Subject: [PATCH] jolly winter cleanup (#251) * ci: bump DeterminateSystems/nix-installer-action from 13 to 16 Bumps [DeterminateSystems/nix-installer-action](https://github.com/determinatesystems/nix-installer-action) from 13 to 16. - [Release notes](https://github.com/determinatesystems/nix-installer-action/releases) - [Commits](https://github.com/determinatesystems/nix-installer-action/compare/v13...v16) --- updated-dependencies: - dependency-name: DeterminateSystems/nix-installer-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * crates: bump serde from 1.0.209 to 1.0.215 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.209 to 1.0.215. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.209...v1.0.215) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * crates: bump serde_json from 1.0.127 to 1.0.133 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.127 to 1.0.133. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.127...v1.0.133) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * crates: bump tokio from 1.40.0 to 1.41.1 Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.40.0 to 1.41.1. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.40.0...tokio-1.41.1) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * crates: bump reqwest from 0.12.7 to 0.12.9 Bumps [reqwest](https://github.com/seanmonstar/reqwest) from 0.12.7 to 0.12.9. - [Release notes](https://github.com/seanmonstar/reqwest/releases) - [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md) - [Commits](https://github.com/seanmonstar/reqwest/compare/v0.12.7...v0.12.9) --- updated-dependencies: - dependency-name: reqwest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * nix: update flake.lock * ci: bump DeterminateSystems/magic-nix-cache-action from 7 to 8 Bumps [DeterminateSystems/magic-nix-cache-action](https://github.com/determinatesystems/magic-nix-cache-action) from 7 to 8. - [Release notes](https://github.com/determinatesystems/magic-nix-cache-action/releases) - [Commits](https://github.com/determinatesystems/magic-nix-cache-action/compare/v7...v8) --- updated-dependencies: - dependency-name: DeterminateSystems/magic-nix-cache-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * treewide: debrand * nix: adopt new darwin sdk * nix: drop treefmt * nix: misc formatting changes * ci: cleanup * nix: pass version info to static builds * nix: mv {derivation,package}.nix * eyre -> anyhow * remove 2024 edition warnings * format with rustfmt * remove optional commands * ci: don't include internal variables in job names * nix: enable for lto builds --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: getchoo-bot[bot] <183349775+getchoo-bot[bot]@users.noreply.github.com> --- .env.template | 2 +- .github/workflows/autobot.yaml | 31 +- .github/workflows/ci.yaml | 87 +++-- .github/workflows/clippy.yaml | 66 ++-- .github/workflows/docker.yaml | 82 ++--- .github/workflows/update-flake.yaml | 44 +-- Cargo.lock | 378 ++++++++++------------ Cargo.toml | 22 +- README.md | 17 +- flake.lock | 29 +- flake.nix | 90 ++++-- nix/containerize.nix | 12 +- nix/derivation.nix | 71 ---- nix/module.nix | 52 +-- nix/package.nix | 60 ++++ nix/static.nix | 20 +- src/client.rs | 32 +- src/commands/general/ask.rs | 8 +- src/commands/general/bing.rs | 2 +- src/commands/general/config.rs | 6 +- src/commands/general/convert.rs | 18 +- src/commands/general/emoji.rs | 2 +- src/commands/general/pfp.rs | 2 +- src/commands/general/random.rs | 44 ++- src/commands/general/version.rs | 4 +- src/commands/mod.rs | 11 - src/commands/moderation/clear_messages.rs | 2 +- src/commands/optional/mod.rs | 2 - src/commands/optional/teawiespam.rs | 30 -- src/commands/optional/uwurandom.rs | 49 --- src/consts.rs | 61 +--- src/events/guild.rs | 2 +- src/events/message.rs | 11 +- src/events/mod.rs | 2 +- src/events/pinboard.rs | 12 +- src/events/reactboard.rs | 10 +- src/http/mod.rs | 4 +- src/http/shiggy.rs | 2 +- src/http/teawie.rs | 4 +- src/main.rs | 5 +- src/storage/mod.rs | 44 +-- src/utils.rs | 4 +- treefmt.nix | 11 - 43 files changed, 621 insertions(+), 826 deletions(-) delete mode 100644 nix/derivation.nix create mode 100644 nix/package.nix delete mode 100644 src/commands/optional/mod.rs delete mode 100644 src/commands/optional/teawiespam.rs delete mode 100644 src/commands/optional/uwurandom.rs delete mode 100644 treefmt.nix diff --git a/.env.template b/.env.template index 6223b8c..82a99ae 100644 --- a/.env.template +++ b/.env.template @@ -2,4 +2,4 @@ TOKEN= REDIS_URL= RUST_BACKTRACE=1 -RUST_LOG="teawiebot=debug,warn" +RUST_LOG="chill=debug,warn" diff --git a/.github/workflows/autobot.yaml b/.github/workflows/autobot.yaml index f1ebe4e..129eb80 100644 --- a/.github/workflows/autobot.yaml +++ b/.github/workflows/autobot.yaml @@ -1,31 +1,34 @@ -name: Auto-merge Dependabot +name: "Auto-merge Dependabot" -on: pull_request +on: + pull_request: jobs: automerge: - name: Check and merge PR - if: github.actor == 'dependabot[bot]' + name: "Check and merge PR" - runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + + runs-on: "ubuntu-latest" steps: - - name: Generate GitHub App token - uses: actions/create-github-app-token@v1 - id: app-token + - name: "Generate GitHub App token" + uses: "actions/create-github-app-token@v1" + id: "app-token" with: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.PRIVATE_KEY }} - - name: Fetch metadata - uses: dependabot/fetch-metadata@v2 - id: metadata + - name: "Fetch metadata" + uses: "dependabot/fetch-metadata@v2" + id: "metadata" with: github-token: ${{ steps.app-token.outputs.token }} - - name: Enable auto-merge + - name: "Enable auto-merge" if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor' }} - run: gh pr merge --auto --squash "$PR" env: - PR: ${{ github.event.pull_request.html_url }} GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR: ${{ github.event.pull_request.html_url }} + run: | + gh pr merge --auto --squash "$PR" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f084a2a..68f9f35 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,8 +1,8 @@ -name: CI +name: "CI" on: push: - branches: [main] + branches: [ "main" ] paths: - "**.nix" - "**.rs" @@ -18,71 +18,64 @@ on: jobs: build: - name: Build + name: "Build (${{ matrix.os }})" strategy: fail-fast: false matrix: - os: [macos-latest, windows-latest] + include: + - os: "ubuntu-latest" + use-nix: true + - os: "windows-latest" + use-nix: false runs-on: ${{ matrix.os }} steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Checkout repository" + uses: "actions/checkout@v4" - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: "Install Nix" + if: ${{ matrix.use-nix }} + uses: "cachix/install-nix-action@v30" - - name: Run build - run: | - cargo build --locked --release - - nix: - name: Nix - - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v13 + - name: "Setup Nix cache" + if: ${{ matrix.use-nix }} + uses: "DeterminateSystems/magic-nix-cache-action@v8" - - name: Setup Nix cache - uses: DeterminateSystems/magic-nix-cache-action@v7 + - name: "Install Rust" + if: ${{ !matrix.use-nix }} + uses: "actions-rust-lang/setup-rust-toolchain@v1" - - name: Run flake checks + - name: "Run cargo build" + if: ${{ !matrix.use-nix }} run: | - nix build --print-build-logs --show-trace - - rustfmt: - name: Rustfmt - - runs-on: ubuntu-latest + cargo build --locked --release - steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Evaluate flake.nix" + if: ${{ matrix.use-nix }} + run: nix flake check --no-build --show-trace - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - components: rustfmt + - name: "Run nix build" + if: ${{ matrix.use-nix }} + run: | + nix build --print-build-logs - - name: Run rustfmt - uses: actions-rust-lang/rustfmt@v1 + - name: "Build Flake checks" + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + nix flake check --print-build-logs release-gate: - name: CI Release gate - needs: [build, rustfmt, nix] + name: "CI Release gate" + needs: [ "build" ] if: ${{ always() }} - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - name: Exit with error - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') - run: exit 1 + - name: "Exit with error" + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: | + exit 1 diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml index cd99256..138e418 100644 --- a/.github/workflows/clippy.yaml +++ b/.github/workflows/clippy.yaml @@ -1,56 +1,54 @@ -name: Clippy +name: "Clippy" on: push: - branches: [main] + branches: [ "main" ] paths: - - 'Cargo.toml' - - 'Cargo.lock' - - '**.rs' + - "**.rs" + - "**.lock" + - "Cargo.toml" + - "flake.nix" + + - ".github/workflows/clippy.yaml" pull_request: paths: - - 'Cargo.toml' - - 'Cargo.lock' - - '**.rs' + - "**.rs" + - "**.lock" + - "Cargo.toml" + - "flake.nix" + + - ".github/workflows/clippy.yaml" workflow_dispatch: jobs: clippy: - name: Run scan + name: "Run scan" - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" permissions: - security-events: write + contents: "read" + security-events: "write" steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Checkout repository" + uses: "actions/checkout@v4" - - name: Install Rust - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - components: clippy + - name: "Install Nix" + uses: "cachix/install-nix-action@v30" - - name: Install SARIF tools - run: | - cargo install clippy-sarif sarif-fmt + - name: "Setup Nix cache" + uses: "DeterminateSystems/magic-nix-cache-action@v8" - - name: Fetch Cargo deps + - name: "Run Clippy" + id: "clippy-run" run: | - cargo fetch --locked + nix build --print-build-logs .#checks.x86_64-linux.clippy-sarif + [ -L result ] || exit 1 + echo "sarif-file=$(readlink -f result)" >> "$GITHUB_OUTPUT" - - name: Run Clippy - continue-on-error: true - run: | - cargo clippy \ - --all-features \ - --all-targets \ - --message-format=json \ - | clippy-sarif | tee /tmp/clippy.sarif | sarif-fmt - - - name: Upload results - uses: github/codeql-action/upload-sarif@v3 + - name: "Upload results" + uses: "github/codeql-action/upload-sarif@v3" with: - sarif_file: /tmp/clippy.sarif + sarif_file: ${{ steps.clippy-run.outputs.sarif-file }} wait-for-processing: true diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 0bb28ad..fe8cffd 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,8 +1,8 @@ -name: Docker +name: "Docker" on: push: - branches: [main] + branches: [ "main" ] paths: - "**.nix" - "**.rs" @@ -18,27 +18,27 @@ on: jobs: build: - name: Build image + name: "Build image" strategy: fail-fast: false matrix: - arch: [amd64, arm64] + arch: [ "amd64", "arm64" ] - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Checkout repository" + uses: "actions/checkout@v4" - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v13 + - name: "Install Nix" + uses: "cachix/install-nix-action@v30" - - name: Setup Nix cache - uses: DeterminateSystems/magic-nix-cache-action@v7 + - name: "Setup Nix cache" + uses: "DeterminateSystems/magic-nix-cache-action@v8" - - name: Build Docker image - id: build + - name: "Build Docker image" + id: "build" env: ARCH: ${{ matrix.arch }} run: | @@ -51,67 +51,69 @@ jobs: [ ! -L result ] && exit 1 echo "path=$(readlink -f ./result)" >> "$GITHUB_OUTPUT" - - name: Upload image - uses: actions/upload-artifact@v4 + - name: "Upload image" + uses: "actions/upload-artifact@v4" with: - name: container-${{ matrix.arch }} + name: "container-${{ matrix.arch }}" path: ${{ steps.build.outputs.path }} - if-no-files-found: error + if-no-files-found: "error" retention-days: 1 release-gate: - name: Docker Release Gate - needs: build + name: "Docker Release Gate" + needs: [ "build" ] - if: always() + if: ${{ always() }} - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - name: Exit with error - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') - run: exit 1 + - name: "Exit with error" + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + run: | + exit 1 push: - name: Push image - needs: release-gate + name: "Push image" + needs: [ "release-gate" ] - if: github.event_name == 'push' + if: ${{ github.event_name == 'push' }} - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" permissions: - packages: write + contents: "read" + packages: "write" env: - REGISTRY: ghcr.io + REGISTRY: "ghcr.io" USERNAME: ${{ github.actor }} - IMAGE_NAME: teawie-bot + IMAGE_NAME: "chill-discord-bot" steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Checkout repository" + uses: "actions/checkout@v4" - - name: Download images - uses: actions/download-artifact@v4 + - name: "Download images" + uses: "actions/download-artifact@v4" with: - path: images + path: "images" - - name: Login to registry - uses: docker/login-action@v3 + - name: "Login to registry" + uses: "docker/login-action@v3" with: registry: ${{ env.REGISTRY }} username: ${{ env.USERNAME }} password: ${{ github.token }} - - name: Push to registry + - name: "Push to registry" env: TAG: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest run: | architectures=("amd64" "arm64") for arch in "${architectures[@]}"; do docker load < images/container-"$arch"/*.tar.gz - docker tag teawie-bot:latest-"$arch" "$TAG"-"$arch" + docker tag chill-discord-bot:latest-"$arch" "$TAG"-"$arch" docker push "$TAG"-"$arch" done diff --git a/.github/workflows/update-flake.yaml b/.github/workflows/update-flake.yaml index 4473811..22e498f 100644 --- a/.github/workflows/update-flake.yaml +++ b/.github/workflows/update-flake.yaml @@ -1,49 +1,51 @@ -name: Update flake.lock +name: "Update flake.lock" on: schedule: - # run every saturday - - cron: "0 0 * * 6" + # Run on the 1st and 15th of every month + - cron: "0 0 1,15 * *" workflow_dispatch: jobs: update: - name: Run update & create PR + name: "Run update & create PR" - runs-on: ubuntu-latest + runs-on: "ubuntu-latest" steps: - - name: Generate GitHub App token - uses: actions/create-github-app-token@v1 - id: app-token + - name: "Generate GitHub App token" + uses: "actions/create-github-app-token@v1" + id: "app-token" with: app-id: ${{ vars.APP_ID }} private-key: ${{ secrets.PRIVATE_KEY }} - - name: Checkout repository - uses: actions/checkout@v4 + - name: "Checkout repository" + uses: "actions/checkout@v4" with: token: ${{ steps.app-token.outputs.token }} - - name: Install Nix - uses: DeterminateSystems/nix-installer-action@v14 + - name: "Install Nix" + uses: "cachix/install-nix-action@v30" - - name: Run update - run: nix flake update + - name: "Run update" + run: | + nix flake update - - name: Create pull request - id: pull-request - uses: peter-evans/create-pull-request@v7 + - name: "Create pull request" + id: "pull-request" + uses: "peter-evans/create-pull-request@v7" with: - branch: update-flake-lock + branch: "update-flake-lock" commit-message: "nix: update flake.lock" title: "nix: update flake.lock" token: ${{ steps.app-token.outputs.token }} sign-commits: true - - name: Enable auto-merge + - name: "Enable auto-merge" if: ${{ env.PR_ID != '' }} - run: gh pr merge --auto --squash "$PR_ID" env: - PR_ID: ${{ steps.pull-request.outputs.pull-request-number }} GH_TOKEN: ${{ steps.app-token.outputs.token }} + PR_ID: ${{ steps.pull-request.outputs.pull-request-number }} + run: | + gh pr merge --auto --squash "$PR_ID" diff --git a/Cargo.lock b/Cargo.lock index 43343cb..9d11cfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,6 +104,12 @@ version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +[[package]] +name = "arc-swap" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" + [[package]] name = "arrayvec" version = "0.7.4" @@ -115,13 +121,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.74" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -271,6 +277,27 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chill" +version = "1.0.0" +dependencies = [ + "anyhow", + "bottomify", + "dotenvy", + "env_logger", + "log", + "poise", + "rand 0.8.5", + "redis 0.27.6", + "redis-macros", + "reqwest 0.12.9", + "serde", + "serde_json", + "tokio", + "url", + "uwurandom-rs", +] + [[package]] name = "chrono" version = "0.4.31" @@ -299,33 +326,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "color-eyre" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -435,7 +435,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -446,7 +446,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -469,6 +469,36 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +[[package]] +name = "deadpool" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6541a3916932fe57768d4be0b1ffb5ec7cbf74ca8c903fdfd5c0fe8aa958f0ed" +dependencies = [ + "deadpool-runtime", + "num_cpus", + "tokio", +] + +[[package]] +name = "deadpool-redis" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e081657a45476ddeefff90d0beb55446a50a77eb76b37387fbd6dd8f8e6210d" +dependencies = [ + "deadpool", + "redis 0.26.1", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" +dependencies = [ + "tokio", +] + [[package]] name = "deranged" version = "0.3.9" @@ -506,6 +536,12 @@ version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "encoding_rs" version = "0.8.33" @@ -563,16 +599,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "eyre" -version = "0.6.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" -dependencies = [ - "indenter", - "once_cell", -] - [[package]] name = "fastrand" version = "2.0.1" @@ -648,7 +674,7 @@ checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -982,12 +1008,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - [[package]] name = "indexmap" version = "2.1.0" @@ -1004,6 +1024,15 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.9" @@ -1019,12 +1048,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.150" @@ -1111,21 +1134,50 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.9", + "libc", +] + [[package]] name = "object" version = "0.32.1" @@ -1147,12 +1199,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1237,7 +1283,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -1278,7 +1324,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -1295,9 +1341,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] @@ -1452,18 +1498,42 @@ dependencies = [ [[package]] name = "redis" -version = "0.25.4" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e902a69d09078829137b4a5d9d082e0490393537badd7c91a3d69d14639e115f" +dependencies = [ + "arc-swap", + "async-trait", + "bytes", + "combine", + "futures-util", + "itoa", + "num-bigint", + "percent-encoding", + "pin-project-lite", + "ryu", + "tokio", + "tokio-util", + "url", +] + +[[package]] +name = "redis" +version = "0.27.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0d7a6955c7511f60f3ba9e86c6d02b3c3f144f8c24b288d1f4e18074ab8bbec" +checksum = "09d8f99a4090c89cc489a94833c901ead69bfbf3877b4867d5482e321ee875bc" dependencies = [ + "arc-swap", "async-trait", "bytes", "combine", "futures-util", + "itertools", "itoa", + "num-bigint", "percent-encoding", "pin-project-lite", - "rustls 0.22.2", + "rustls 0.23.7", "rustls-native-certs", "rustls-pemfile 2.1.1", "rustls-pki-types", @@ -1471,18 +1541,19 @@ dependencies = [ "sha1_smol", "socket2 0.5.5", "tokio", - "tokio-rustls 0.25.0", + "tokio-rustls 0.26.0", "tokio-util", "url", ] [[package]] name = "redis-macros" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b5407866b6626d251b18c878f043d37f43124680f26a806595a61714ab049a" +checksum = "90a7a4a7b88300d28a3251c64b5c74e57e46c0cd2238cce81ec0927793255e49" dependencies = [ - "redis", + "deadpool-redis", + "redis 0.27.6", "redis-macros-derive", "serde", "serde_json", @@ -1490,13 +1561,13 @@ dependencies = [ [[package]] name = "redis-macros-derive" -version = "0.3.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dfe1dc77e38e260bbd53e98d3aec64add3cdf5d773e38d344c63660196117f5" +checksum = "d48e124e31d75d8d8ab9a309df06c503c79aebf7b930c5284b9be884f35844d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -1583,9 +1654,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.7" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.0", "bytes", @@ -1680,20 +1751,6 @@ dependencies = [ "sct", ] -[[package]] -name = "rustls" -version = "0.22.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e87c9956bd9807afa1f77e0f7594af32566e830e088a5576d27c5b6f30f49d41" -dependencies = [ - "log", - "ring", - "rustls-pki-types", - "rustls-webpki 0.102.2", - "subtle", - "zeroize", -] - [[package]] name = "rustls" version = "0.23.7" @@ -1851,29 +1908,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.209" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "itoa", "memchr", @@ -1942,15 +1999,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2053,9 +2101,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -2104,28 +2152,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" -[[package]] -name = "teawie-bot" -version = "1.0.0" -dependencies = [ - "bottomify", - "color-eyre", - "dotenvy", - "env_logger", - "eyre", - "log", - "poise", - "rand 0.8.5", - "redis", - "redis-macros", - "reqwest 0.12.7", - "serde", - "serde_json", - "tokio", - "url", - "uwurandom-rs", -] - [[package]] name = "tempfile" version = "3.9.0" @@ -2165,17 +2191,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if", - "once_cell", + "syn 2.0.87", ] [[package]] @@ -2226,9 +2242,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.40.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -2249,7 +2265,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -2262,17 +2278,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-rustls" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "775e0c0f0adb3a2f22a00c4745d728b479985fc15ee7ca6a2608388c5569860f" -dependencies = [ - "rustls 0.22.2", - "rustls-pki-types", - "tokio", -] - [[package]] name = "tokio-rustls" version = "0.26.0" @@ -2361,7 +2366,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -2371,28 +2376,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" -dependencies = [ - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "sharded-slab", - "thread_local", - "tracing-core", ] [[package]] @@ -2465,7 +2448,7 @@ checksum = "0b122284365ba8497be951b9a21491f70c9688eb6fddc582931a0703f6a00ece" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", ] [[package]] @@ -2563,12 +2546,6 @@ dependencies = [ "uwurandom-proc-macros", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vec_map" version = "0.8.2" @@ -2614,26 +2591,27 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -2651,9 +2629,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2661,22 +2639,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-streams" diff --git a/Cargo.toml b/Cargo.toml index 6803683..473bd01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,32 +1,28 @@ [package] -name = "teawie-bot" +name = "chill" version = "1.0.0" edition = "2021" -repository = "https://github.com/getchoo/teawieBot" +repository = "https://github.com/getchoo/chill" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +anyhow = "1.0" bottomify = "1.2.0" -color-eyre = "0.6.3" dotenvy = "0.15.7" env_logger = "0.11.5" -eyre = { version = "0.6.12", default-features = false, features = [ - "auto-install", - "track-caller", -] } log = "0.4.22" poise = "0.6.1" rand = "0.8.5" -redis = { version = "0.25.4", features = ["tokio-comp", "tokio-rustls-comp"] } -redis-macros = "0.3.0" -reqwest = { version = "0.12.7", default-features = false, features = [ +redis = { version = "0.27", features = ["tokio-comp", "tokio-rustls-comp"] } +redis-macros = "0.4" +reqwest = { version = "0.12.9", default-features = false, features = [ "rustls-tls", "json", ] } -serde = "1.0.209" -serde_json = "1.0.127" -tokio = { version = "1.40.0", features = [ +serde = "1.0.215" +serde_json = "1.0.133" +tokio = { version = "1.41.1", features = [ "macros", "rt-multi-thread", "signal", diff --git a/README.md b/README.md index 9b8f719..8725b30 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,5 @@ -# teawie bot 🦀🦀🦀 +# chill -[![CI](https://github.com/getchoo/teawieBot/actions/workflows/ci.yaml/badge.svg?event=push)](https://github.com/getchoo/teawieBot/actions/workflows/ci.yaml) +[![CI](https://github.com/getchoo/chill/actions/workflows/ci.yaml/badge.svg?event=push)](https://github.com/getchoo/chill/actions/workflows/ci.yaml) -okay so like basically, it's just a discord bot named "teawie" (so cool!! -and now in rust!!!)🚀🚀 - -## features / commands - -**!ask** | ask the bot a question with predefined answers -(this is also a slash command, use with /ask) - -**!teawiespam** | spams :teawiesmile: - -**/random_teawie** | sends out a random teawie, which is a soft cute character made -by SympathyTea +okay so like basically, it's just a discord bot (so cool!!) diff --git a/flake.lock b/flake.lock index b1c3ae1..606c472 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1724363052, - "narHash": "sha256-Nf/iQWamRVAwAPFccQMfm5Qcf+rLLnU1rWG3f9orDVE=", + "lastModified": 1733935885, + "narHash": "sha256-xyiHLs6KJ1fxeGmcCxKjJE4yJknVJxbC8Y/ZRYyC8WE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5de1564aed415bf9d0f281461babc2d101dd49ff", + "rev": "5a48e3c2e435e95103d56590188cfed7b70e108c", "type": "github" }, "original": { @@ -18,28 +18,7 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1724338379, - "narHash": "sha256-kKJtaiU5Ou+e/0Qs7SICXF22DLx4V/WhG1P6+k4yeOE=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "070f834771efa715f3e74cd8ab93ecc96fabc951", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index e03e35d..0e86328 100644 --- a/flake.nix +++ b/flake.nix @@ -1,26 +1,17 @@ { - description = "teawie moment"; - inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - - ## Everything below this is optional - ## `inputs..follows = ""` - - treefmt-nix = { - url = "github:numtide/treefmt-nix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = { self, nixpkgs, - treefmt-nix, }: + let inherit (nixpkgs) lib; + systems = [ "x86_64-linux" "aarch64-linux" @@ -29,19 +20,66 @@ ]; forAllSystems = lib.genAttrs systems; - nixpkgsFor = forAllSystems (system: nixpkgs.legacyPackages.${system}); - treefmtFor = forAllSystems (system: treefmt-nix.lib.evalModule nixpkgsFor.${system} ./treefmt.nix); in { - checks = forAllSystems (system: { - treefmt = treefmtFor.${system}.config.build.check self; - }); + checks = forAllSystems ( + system: + + let + pkgs = nixpkgs.legacyPackages.${system}; + + mkCheck = + name: nativeBuildInputs: script: + pkgs.runCommand "check-${name}" { inherit nativeBuildInputs; } '' + ${script} | tee $out + ''; + in + + { + clippy-sarif = pkgs.stdenv.mkDerivation { + name = "check-clippy-sarif"; + inherit (self.packages.${system}.chill-discord-bot) src cargoDeps; + + nativeBuildInputs = [ + pkgs.cargo + pkgs.clippy + pkgs.clippy-sarif + pkgs.rustPlatform.cargoSetupHook + pkgs.rustc + pkgs.sarif-fmt + ]; + + buildPhase = '' + runHook preBuild + + cargo clippy \ + --all-features \ + --all-targets \ + --tests \ + --message-format=json \ + | clippy-sarif | tee $out | sarif-fmt + + runHook postBuild + ''; + }; + + actionlint = mkCheck "actionlint" [ pkgs.actionlint ] "actionlint ${self}/.github/workflows/*"; + deadnix = mkCheck "deadnix" [ pkgs.deadnix ] "deadnix check ${self}"; + nixfmt = mkCheck "nixfmt" [ + pkgs.nixfmt-rfc-style + ] "find ${self} -type f -name '*.nix' | xargs nixfmt --check"; + rustfmt = mkCheck "rustfmt" [ pkgs.cargo pkgs.rustfmt ] "cd ${self} && cargo fmt -- --check"; + statix = mkCheck "statix" [ pkgs.statix ] "statix check ${self}"; + } + ); devShells = forAllSystems ( system: + let - pkgs = nixpkgsFor.${system}; + pkgs = nixpkgs.legacyPackages.${system}; in + { default = pkgs.mkShell { packages = [ @@ -61,7 +99,7 @@ pkgs.redis ]; - inputsFrom = [ self.packages.${system}.teawie-bot ]; + inputsFrom = [ self.packages.${system}.chill-discord-bot ]; RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; }; @@ -73,24 +111,26 @@ self.formatter.${system} ]; - inputsFrom = [ self.packages.${system}.teawie-bot ]; + inputsFrom = [ self.packages.${system}.chill-discord-bot ]; }; } ); - formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style); + formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style); - nixosModules.default = import ./nix/module.nix self; + nixosModules.default = lib.modules.importApply ./nix/module.nix { inherit self; }; packages = forAllSystems ( system: + let - pkgs = nixpkgsFor.${system}; + pkgs = nixpkgs.legacyPackages.${system}; packages' = self.packages.${system}; - staticWith = pkgs.callPackage ./nix/static.nix { inherit (packages') teawie-bot; }; + staticWith = pkgs.callPackage ./nix/static.nix { inherit self; }; containerize = pkgs.callPackage ./nix/containerize.nix { }; in + { container-amd64 = containerize packages'.static-x86_64; container-arm64 = containerize packages'.static-aarch64; @@ -98,9 +138,9 @@ static-x86_64 = staticWith { arch = "x86_64"; }; static-aarch64 = staticWith { arch = "aarch64"; }; - teawie-bot = pkgs.callPackage ./nix/derivation.nix { inherit self; }; + chill-discord-bot = pkgs.callPackage ./nix/package.nix { inherit self; }; - default = self.packages.${system}.teawie-bot; + default = self.packages.${system}.chill-discord-bot; } ); }; diff --git a/nix/containerize.nix b/nix/containerize.nix index 8175e17..b936b90 100644 --- a/nix/containerize.nix +++ b/nix/containerize.nix @@ -1,17 +1,21 @@ { lib, dockerTools }: + let containerize = - teawie-bot: + chill-discord-bot: + let - inherit (teawie-bot.passthru) crossPkgs; + inherit (chill-discord-bot.passthru) crossPkgs; architecture = crossPkgs.go.GOARCH; in + dockerTools.buildLayeredImage { - name = "teawie-bot"; + name = "chill-discord-bot"; tag = "latest-${architecture}"; contents = [ dockerTools.caCertificates ]; - config.Cmd = [ (lib.getExe teawie-bot) ]; + config.Cmd = [ (lib.getExe chill-discord-bot) ]; inherit architecture; }; in + containerize diff --git a/nix/derivation.nix b/nix/derivation.nix deleted file mode 100644 index 955f601..0000000 --- a/nix/derivation.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ - lib, - stdenv, - rustPlatform, - darwin, - self ? { }, - lto ? true, - optimizeSize ? false, -}: -let - fs = lib.fileset; -in -rustPlatform.buildRustPackage { - pname = "teawie-bot"; - version = (lib.importTOML ../Cargo.toml).package.version or "unknown"; - - src = fs.toSource { - root = ../.; - fileset = fs.intersection (fs.gitTracked ../.) ( - lib.fileset.unions [ - ../src - ../Cargo.toml - ../Cargo.lock - ] - ); - }; - - cargoLock = { - lockFile = ../Cargo.lock; - }; - - buildInputs = lib.optionals stdenv.isDarwin ( - with darwin.apple_sdk.frameworks; - [ - CoreFoundation - Security - SystemConfiguration - darwin.libiconv - ] - ); - - env = - let - toRustFlags = lib.mapAttrs' ( - name: - lib.nameValuePair "CARGO_BUILD_RELEASE_${ - lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] name) - }" - ); - in - { - GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown"; - } - // lib.optionalAttrs lto (toRustFlags { - lto = "thin"; - }) - // lib.optionalAttrs optimizeSize (toRustFlags { - codegen-units = 1; - opt-level = "s"; - panic = "abort"; - strip = "symbols"; - }); - - meta = { - description = "funni bot"; - homepage = "https://github.com/getchoo/teawiebot"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ getchoo ]; - mainProgram = "teawie-bot"; - }; -} diff --git a/nix/module.nix b/nix/module.nix index 4e3b683..8220e3f 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -5,14 +5,11 @@ self: pkgs, ... }: -let - cfg = config.services.teawiebot; - defaultUser = "teawiebot"; +let inherit (lib) getExe literalExpression - mdDoc mkEnableOption mkIf mkOption @@ -20,17 +17,22 @@ let optionals types ; - inherit (pkgs.stdenv.hostPlatform) system; + + cfg = config.services.chill-discord-bot; + + defaultUser = "chill-discord-bot"; + flakePackages = self.packages.${system} or (throw "getchoo/chill: ${system} is not supported"); in + { - options.services.teawiebot = { - enable = mkEnableOption "teawieBot"; - package = mkPackageOption (self.packages.${system} or (builtins.throw "${system} is not supported!") - ) "teawie-bot" { }; + options.services.chill-discord-bot = { + enable = mkEnableOption "chill"; + + package = mkPackageOption flakePackages "chill-discord-bot" { }; user = mkOption { - description = mdDoc '' + description = '' User under which the service should run. If this is the default value, the user will be created, with the specified group as the primary group. @@ -43,7 +45,7 @@ in }; group = mkOption { - description = mdDoc '' + description = '' Group under which the service should run. If this is the default value, the group will be created. ''; @@ -55,7 +57,7 @@ in }; redisUrl = mkOption { - description = mdDoc '' + description = '' Connection to a redis server. If this needs to include credentials that shouldn't be world-readable in the Nix store, set environmentFile and override the `REDIS_URL` entry. @@ -69,28 +71,36 @@ in }; environmentFile = mkOption { - description = mdDoc '' + description = '' Environment file as defined in {manpage}`systemd.exec(5)` ''; type = types.nullOr types.path; default = null; example = literalExpression '' - "/run/agenix.d/1/teawieBot" + "/run/agenix.d/1/chillDiscordBot" ''; }; }; + imports = [ + (lib.mkRenamedOptionModule [ "services" "teawiebot" ] [ "services" "chill-discord-bot" ]) + ]; + config = mkIf cfg.enable { - services.redis.servers.teawiebot = mkIf (cfg.redisUrl == "local") { - enable = true; - inherit (cfg) user; - port = 0; # disable tcp listener + services.redis.servers = mkIf (cfg.redisUrl == "local") { + chill-discord-bot = { + enable = true; + inherit (cfg) user; + port = 0; # disable tcp listener + }; }; - systemd.services."teawiebot" = { + systemd.services.chill-discord-bot = { enable = true; wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ] ++ optionals (cfg.redisUrl == "local") [ "redis-teawiebot.service" ]; + after = [ + "network.target" + ] ++ optionals (cfg.redisUrl == "local") [ "redis-chill-discord-bot.service" ]; script = '' ${getExe cfg.package} @@ -99,7 +109,7 @@ in environment = { REDIS_URL = if cfg.redisUrl == "local" then - "unix:${config.services.redis.servers.teawiebot.unixSocket}" + "unix:${config.services.redis.servers.chill-discord-bot.unixSocket}" else cfg.redisUrl; }; diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..abb3129 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,60 @@ +{ + lib, + rustPlatform, + self ? { }, + lto ? true, + optimizeSize ? false, +}: + +let + fs = lib.fileset; +in + +rustPlatform.buildRustPackage { + pname = "chill-discord-bot"; + version = (lib.importTOML ../Cargo.toml).package.version or "unknown"; + + src = fs.toSource { + root = ../.; + fileset = fs.intersection (fs.gitTracked ../.) ( + lib.fileset.unions [ + ../src + ../Cargo.toml + ../Cargo.lock + ] + ); + }; + + cargoLock.lockFile = ../Cargo.lock; + + # `-C panic="abort"` breaks checks + doCheck = !optimizeSize; + + RUSTFLAGS = + lib.optionals lto [ + "-C" + "embed-bitcode=yes" + "-C" + "lto=thin" + ] + ++ lib.optionals optimizeSize [ + "-C" + "codegen-units=1" + "-C" + "opt-level=s" + "-C" + "panic=abort" + "-C" + "strip=symbols" + ]; + + GIT_SHA = self.shortRev or self.dirtyShortRev or "unknown"; + + meta = { + description = "funni bot"; + homepage = "https://github.com/getchoo/chill"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ getchoo ]; + mainProgram = "chill"; + }; +} diff --git a/nix/static.nix b/nix/static.nix index 5a5606f..1c9ac42 100644 --- a/nix/static.nix +++ b/nix/static.nix @@ -1,20 +1,28 @@ { lib, pkgsCross, - teawie-bot, + self, }: + let crossPkgsFor = with pkgsCross; { x86_64 = musl64.pkgsStatic; aarch64 = aarch64-multiplatform.pkgsStatic; }; in + { arch }: + let crossPkgs = crossPkgsFor.${arch}; in -(crossPkgs.callPackage ./derivation.nix { optimizeSize = true; }).overrideAttrs (old: { - passthru = old.passthru or { } // { - inherit crossPkgs; - }; -}) + +(crossPkgs.callPackage ./package.nix { + inherit self; + optimizeSize = true; +}).overrideAttrs + (old: { + passthru = old.passthru or { } // { + inherit crossPkgs; + }; + }) diff --git a/src/client.rs b/src/client.rs index 65c221b..cec59da 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,14 +2,14 @@ use crate::{commands, events, http, storage::Storage}; use std::{sync::Arc, time::Duration}; -use eyre::{bail, Context as _, Result}; -use log::{info, trace, warn}; +use anyhow::{Context as _, Result}; +use log::{info, warn}; use poise::{ serenity_prelude::{self as serenity}, EditTracker, Framework, FrameworkOptions, PrefixFrameworkOptions, }; -pub type Error = eyre::Report; +pub type Error = anyhow::Error; pub type Context<'a> = poise::Context<'a, Data, Error>; #[derive(Clone, Debug, Default)] @@ -21,28 +21,8 @@ pub struct Data { async fn setup(ctx: &serenity::Context) -> Result { let storage = Storage::from_env().ok(); - if let Some(storage) = storage.as_ref() { - if !storage.clone().is_connected() { - bail!("You specified a storage backend but there's no connection! Is it running?"); - } - trace!("Storage backend connected!"); - - poise::builtins::register_globally(ctx, &commands::global()).await?; - info!("Registered global commands!"); - - // register "extra" commands in guilds that allow it - let guilds = storage.get_opted_guilds().await?; - - for guild in guilds { - poise::builtins::register_in_guild(ctx, &commands::optional(), guild).await?; - - info!("Registered guild commands to {}", guild); - } - } else { - warn!("No storage backend was specified. Features requiring storage cannot be used"); - warn!("Registering optional commands globally since there's no storage backend"); - poise::builtins::register_globally(ctx, &commands::all()).await?; - } + poise::builtins::register_globally(ctx, &commands::all()).await?; + info!("Registered global commands!"); let http_client = ::default(); let data = Data { @@ -60,7 +40,7 @@ pub async fn handle_shutdown(shard_manager: Arc, reason: } pub async fn get() -> Result { - let token = std::env::var("TOKEN").wrap_err("Couldn't find bot token in environment!")?; + let token = std::env::var("TOKEN").context("Couldn't find bot token in environment!")?; let intents = serenity::GatewayIntents::non_privileged() | serenity::GatewayIntents::MESSAGE_CONTENT; diff --git a/src/commands/general/ask.rs b/src/commands/general/ask.rs index 1300e97..8d83622 100644 --- a/src/commands/general/ask.rs +++ b/src/commands/general/ask.rs @@ -1,18 +1,18 @@ use crate::{client::Context, consts, utils}; -use eyre::{Context as _, Result}; +use anyhow::{Context as _, Result}; -/// Ask teawie a question! +/// Ask a question! #[poise::command(prefix_command, slash_command)] #[allow(clippy::no_effect_underscore_binding)] pub async fn ask( ctx: Context<'_>, #[rename = "question"] - #[description = "The question you want to ask teawie"] + #[description = "The question you want to ask"] _question: String, ) -> Result<()> { let resp = utils::random_choice(consts::RESPONSES) - .wrap_err("Couldn't choose from random responses!")?; + .context("Couldn't choose from random responses!")?; ctx.say(resp).await?; Ok(()) diff --git a/src/commands/general/bing.rs b/src/commands/general/bing.rs index 28fdf0d..8390659 100644 --- a/src/commands/general/bing.rs +++ b/src/commands/general/bing.rs @@ -1,6 +1,6 @@ use crate::client::Context; -use eyre::Result; +use anyhow::Result; /// Make sure the wie is alive #[poise::command(prefix_command)] diff --git a/src/commands/general/config.rs b/src/commands/general/config.rs index 6adb78b..bdc102e 100644 --- a/src/commands/general/config.rs +++ b/src/commands/general/config.rs @@ -3,7 +3,7 @@ use crate::storage::settings::{Properties, Settings}; use std::str::FromStr; -use eyre::{OptionExt as _, Result}; +use anyhow::{Context as _, Result}; use log::debug; use poise::serenity_prelude::{CreateEmbed, GuildChannel, ReactionType}; use poise::{ChoiceParameter, CreateReply}; @@ -70,7 +70,7 @@ pub async fn set( #[description = "Minimum number of reactions a message needs to make it to the ReactBoard (defaults to 5)"] reactboard_requirement: Option, #[description = "Toggle ReactBoard"] reactboard_enabled: Option, - #[description = "Enables 'extra' commands like teawiespam and copypasta. Defaults to false."] + #[description = "Enables 'extra' commands like uwurandom. Defaults to false."] optional_commands_enabled: Option, ) -> Result<()> { if let Some(storage) = &ctx.data().storage { @@ -152,7 +152,7 @@ pub async fn get( ) -> Result<()> { let gid = &ctx .guild_id() - .ok_or_eyre("Failed to get GuildId from context!")?; + .context("Failed to get GuildId from context!")?; if let Some(storage) = &ctx.data().storage { let settings = storage.get_guild_settings(gid).await?; diff --git a/src/commands/general/convert.rs b/src/commands/general/convert.rs index b5e7018..a736ccf 100644 --- a/src/commands/general/convert.rs +++ b/src/commands/general/convert.rs @@ -1,7 +1,7 @@ use crate::client::Context; +use anyhow::Result; use bottomify::bottom; -use eyre::Result; use poise::serenity_prelude::constants::MESSAGE_CODE_LIMIT; #[allow(clippy::unused_async)] @@ -13,44 +13,44 @@ pub async fn convert(_: Context<'_>) -> Result<()> { Ok(()) } -/// Ask teawie to convert °F to °C +/// Convert °F to °C #[poise::command(slash_command)] pub async fn to_celsius( ctx: Context<'_>, - #[description = "What teawie will convert"] degrees_fahrenheit: f32, + #[description = "What to convert"] degrees_fahrenheit: f32, ) -> Result<()> { let temp = (degrees_fahrenheit - 32.0) * (5.0 / 9.0); ctx.say(temp.to_string()).await?; Ok(()) } -/// Ask teawie to convert °C to °F +/// Convert °C to °F #[poise::command(slash_command)] pub async fn to_fahrenheit( ctx: Context<'_>, - #[description = "What teawie will convert"] degrees_celsius: f32, + #[description = "What to convert"] degrees_celsius: f32, ) -> Result<()> { let temp = (degrees_celsius * (9.0 / 5.0)) + 32.0; ctx.say(temp.to_string()).await?; Ok(()) } -/// Teawie will translate to bottom 🥺 +/// Translate to bottom 🥺 #[poise::command(slash_command)] pub async fn to_bottom( ctx: Context<'_>, - #[description = "What teawie will translate into bottom"] message: String, + #[description = "What to translate into bottom"] message: String, ) -> Result<()> { let encoded = bottom::encode_string(&message); ctx.say(encoded).await?; Ok(()) } -/// Teawie will translate from bottom 🥸 +/// Translate from bottom 🥸 #[poise::command(slash_command)] pub async fn from_bottom( ctx: Context<'_>, - #[description = "What teawie will translate from bottom"] message: String, + #[description = "What to translate from bottom"] message: String, ) -> Result<()> { let resp: String; diff --git a/src/commands/general/emoji.rs b/src/commands/general/emoji.rs index bbae0b5..d91b50c 100644 --- a/src/commands/general/emoji.rs +++ b/src/commands/general/emoji.rs @@ -1,6 +1,6 @@ use crate::{client::Context, consts::Colors}; -use eyre::Result; +use anyhow::Result; use poise::{ serenity_prelude::{CreateEmbed, Emoji}, CreateReply, diff --git a/src/commands/general/pfp.rs b/src/commands/general/pfp.rs index 34ae795..9040b9b 100644 --- a/src/commands/general/pfp.rs +++ b/src/commands/general/pfp.rs @@ -1,6 +1,6 @@ use crate::{client::Context, consts::Colors}; -use eyre::Result; +use anyhow::Result; use poise::{ serenity_prelude::{CreateEmbed, User}, CreateReply, diff --git a/src/commands/general/random.rs b/src/commands/general/random.rs index 094123b..053e4bb 100644 --- a/src/commands/general/random.rs +++ b/src/commands/general/random.rs @@ -1,22 +1,14 @@ -use crate::{client::Context, consts, http, utils}; +use crate::{client::Context, http, utils}; -use eyre::Result; +use anyhow::Result; +use rand::Rng; -#[poise::command(slash_command, subcommands("lore", "teawie", "shiggy"))] +#[poise::command(slash_command, subcommands("teawie", "shiggy", "uwu"))] #[allow(clippy::unused_async)] pub async fn random(_: Context<'_>) -> Result<()> { Ok(()) } -/// Get a random piece of teawie lore! -#[poise::command(prefix_command, slash_command)] -pub async fn lore(ctx: Context<'_>) -> Result<()> { - let resp = utils::random_choice(consts::LORE)?; - ctx.say(resp).await?; - - Ok(()) -} - /// Get a random teawie #[poise::command(prefix_command, slash_command)] pub async fn teawie(ctx: Context<'_>) -> Result<()> { @@ -34,3 +26,31 @@ pub async fn shiggy(ctx: Context<'_>) -> Result<()> { Ok(()) } + +/// Some uwu +#[poise::command(prefix_command, slash_command)] +pub async fn uwu( + ctx: Context<'_>, + #[description = "The amount of uwurandom to generate"] + #[min = 1] + #[max = 100] + length: Option, +) -> Result<()> { + let length = length.unwrap_or(rand::thread_rng().gen_range(1..50)); + + let mut result = String::with_capacity(length as usize); + // ThreadRng is not Send(obviously), and rustc is slightly too paranoid about rng spilling to await point + // So calm it by constraining it to a block + { + let mut rng = rand::thread_rng(); + let mut state_machine = uwurandom_rs::StateMachine::new(&mut rng); + for _ in 0..length { + let generated; + (state_machine, generated) = state_machine.generate(&mut rng); + result.push(generated); + } + } + ctx.say(result).await?; + + Ok(()) +} diff --git a/src/commands/general/version.rs b/src/commands/general/version.rs index bdf6805..34513fc 100644 --- a/src/commands/general/version.rs +++ b/src/commands/general/version.rs @@ -2,7 +2,7 @@ use crate::{client::Context, consts::Colors}; use std::env::consts::{ARCH, OS}; -use eyre::Result; +use anyhow::Result; use poise::{serenity_prelude::CreateEmbed, CreateReply}; /// Get version info @@ -12,7 +12,7 @@ pub async fn version(ctx: Context<'_>) -> Result<()> { let revision_url = format!( "[{}]({}/tree/{})", sha, - option_env!("CARGO_PKG_REPOSITORY").unwrap_or("https://github.com/getchoo/teawieBot"), + option_env!("CARGO_PKG_REPOSITORY").unwrap_or("https://github.com/getchoo/chill"), sha, ); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b8d0381..14b7b2b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -2,7 +2,6 @@ use crate::client::{Data, Error}; mod general; mod moderation; -mod optional; type Command = poise::Command; @@ -18,12 +17,6 @@ macro_rules! cmd { } pub fn all() -> Vec { - let mut all_commands = global(); - all_commands.append(&mut optional()); - all_commands -} - -pub fn global() -> Vec { vec![ cmd!(general, ask), cmd!(general, bing), @@ -36,7 +29,3 @@ pub fn global() -> Vec { cmd!(moderation, clear_messages), ] } - -pub fn optional() -> Vec { - vec![cmd!(optional, teawiespam), cmd!(optional, uwurandom)] -} diff --git a/src/commands/moderation/clear_messages.rs b/src/commands/moderation/clear_messages.rs index 65a30be..11a7ef8 100644 --- a/src/commands/moderation/clear_messages.rs +++ b/src/commands/moderation/clear_messages.rs @@ -1,6 +1,6 @@ use crate::client::Context; -use eyre::Result; +use anyhow::Result; use log::debug; use poise::serenity_prelude::GetMessages; diff --git a/src/commands/optional/mod.rs b/src/commands/optional/mod.rs deleted file mode 100644 index a3d1bd2..0000000 --- a/src/commands/optional/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod teawiespam; -pub mod uwurandom; diff --git a/src/commands/optional/teawiespam.rs b/src/commands/optional/teawiespam.rs deleted file mode 100644 index bfac852..0000000 --- a/src/commands/optional/teawiespam.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::client::Context; - -use eyre::Result; -use log::debug; - -/// teawie will spam you. -#[poise::command(slash_command)] -pub async fn teawiespam(ctx: Context<'_>) -> Result<()> { - if let Some(guild_id) = ctx.guild_id() { - if let Some(storage) = &ctx.data().storage { - let settings = storage.get_guild_settings(&guild_id).await?; - - if !settings.optional_commands_enabled { - debug!("Not running command in {guild_id} since it's disabled"); - ctx.say("I'm not allowed to do that here").await?; - - return Ok(()); - } - } else { - debug!("Ignoring restrictions on command; no storage backend is attached!"); - } - } else { - debug!("Ignoring restrictions on command; we're not in a guild."); - } - - let wies = "<:teawiesmile:1056438046440042546>".repeat(50); - ctx.say(wies).await?; - - Ok(()) -} diff --git a/src/commands/optional/uwurandom.rs b/src/commands/optional/uwurandom.rs deleted file mode 100644 index c952dee..0000000 --- a/src/commands/optional/uwurandom.rs +++ /dev/null @@ -1,49 +0,0 @@ -use crate::client::Context; - -use eyre::Result; -use log::debug; -use rand::Rng; - -/// Generate some amount of uwurandom -#[poise::command(slash_command)] -pub async fn uwurandom( - ctx: Context<'_>, - #[description = "The amount of uwurandom to generate"] - #[min = 1] - #[max = 2000] - length: Option, -) -> Result<()> { - if let Some(guild_id) = ctx.guild_id() { - if let Some(storage) = &ctx.data().storage { - let settings = storage.get_guild_settings(&guild_id).await?; - - if !settings.optional_commands_enabled { - debug!("Not running command in {guild_id} since it's disabled"); - ctx.say("I'm not allowed to do that here").await?; - - return Ok(()); - } - } else { - debug!("Ignoring restrictions on command; no storage backend is attached!"); - } - } else { - debug!("Ignoring restrictions on command; we're not in a guild"); - } - - let length = length.unwrap_or(rand::thread_rng().gen_range(1..50)); - - let mut result = String::with_capacity(length as usize); - // ThreadRng is not Send(obviously), and rustc is slightly too paranoid about rng spilling to await point - // So calm it by constraining it to a block - { - let mut rng = rand::thread_rng(); - let mut state_machine = uwurandom_rs::StateMachine::new(&mut rng); - for _ in 0..length { - let generated; - (state_machine, generated) = state_machine.generate(&mut rng); - result.push(generated); - } - } - ctx.say(result).await?; - Ok(()) -} diff --git a/src/consts.rs b/src/consts.rs index 0b12334..031a5e4 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -31,71 +31,12 @@ pub fn bot_scopes() -> &'static Vec { BOT_SCOPES.get_or_init(|| vec![Scope::Bot, Scope::ApplicationsCommands]) } -pub const TEAMOJIS: [&str; 15] = [ - "<:teawiecry:1056438041872433303>", - "<:teawiederp:1056438043109757018>", - "<:teawiedizzy:1056438044149960794>", - "<:teawienerdcroppedanddownsized:1056438150123233320>", - "<:teawieneutral:1056438044930084928>", - "", - "", - "", - "<:teawiesmile:1056438046440042546>", - "<:teawiesmug:1056438047362781216>", - "<:teawiestarstruck:1056438048721744022>", - "<:tei:1066249455281655908>", - "<:wavy:1066518302974812180>", - "<:wie:1066249592489902080>", - "<:manythoughtsheadfull:1065887153399283742>", -]; - -pub const RESPONSES: [&str; 20] = [ +pub const RESPONSES: [&str; 5] = [ "soon", "maybe", "perhaps", "elaborate", "Twitter's Recommendation Algorithm", - // i was lazy here - "<:teawiecry:1056438041872433303>", - "<:teawiederp:1056438043109757018>", - "<:teawiedizzy:1056438044149960794>", - "<:teawienerdcroppedanddownsized:1056438150123233320>", - "<:teawieneutral:1056438044930084928>", - "", - "", - "", - "<:teawiesmile:1056438046440042546>", - "<:teawiesmug:1056438047362781216>", - "<:teawiestarstruck:1056438048721744022>", - "<:tei:1066249455281655908>", - "<:wavy:1066518302974812180>", - "<:wie:1066249592489902080>", - "<:manythoughtsheadfull:1065887153399283742>", -]; - -pub const LORE: [&str; 22] = [ - "Teawie is made of silly string and blood.", - "Teawie has the mentality of an eight year old, but no discernable age.", - "Teawie can change size to fit into tight spaces. Although he prefers to be small most of the time.", - "Teawie is blue flavored. The color specifically.", - "Teawie produces asexually via mitosis and in other cells.", - "Teawie cannot be physically damaged, and if put into a blender of some sort, will become stretchy.", - "Teawie has one tooth, but originally had a full set. These were lost due to him constantly eating stuff he probably shouldn't, such as computer hardware.", - "Teawie smells like cotton candy and fiberglass insulation.", - "Teawie at a base \"knowledge level\", can only repeat his name. However this can be changed if Teawie inherits \"strings\" of information from a host.", - "Teawie can \"infect\" other cells and turn them into Teawie.", - "Teawie has a gun, but the only bullets it has is smaller Teawies. They have the same attributes as Teawie, so they perform mitosis to keep the clip stocked.", - "The gun resembles the Ray Gun from the Call of Duty series. However this gun is blue rather than red.", - "Teawie \"bullets\" typically lodge into parts of a body and proceed to infect the victim. If a Teawie ends up lodged into the brain, Teawie will be inside the mind of the user, reigning pure terror until the victim passes on. Teawie will pilot the victim like a meat suit until decomposition fully occurs, and then find a new host.", - "A Teawie \"bullet\" will usually kill the host upon impact, However if the host survives, they will exhibit symptoms such as lightheadedness, fainting, fatigue, delusions, mental confusion and decline, disorientation, hallucinations and eventually death.", - "If a host possesses particular \"strings\" of information that a Teawie does not currently possess, Teawie will add those current strings to himself once the host expires. Essentially giving Teawie the host's memories and knowledge. This starts to debilitate overtime. Eventually ending right back where the Teawie started.", - "Teawie is capable of infecting non-organic material such as a Personal Computer. If infecting something with quite a bit of power, Teawie will inherit \"strings\" from the object and become more powerful as a result.", - "Teawie himself isnt radioactive however some Teawies have a pretty bad habit of being in or around places with incredibly high radiation.", - "Teawie has a Go-Kart that he will sometimes drive around in, however due to being mentally eight years old at a base \"knowledge level\", he is not good at all with driving. Despite numerous crashes, he always ends up unscathed.", - "Teawie will \"insert\" himself into various media while trying to move from host to host.", - "Teawie is described as \"chewy\" in texture.", - "Teawie is friends with Blåhaj.", - "Consuming Teawie, and other Teawie variants is not recommended, since it will allow Teawie to take over the consumer in the same way as being shot with a Teawie \"bullet\".", ]; pub enum Colors { diff --git a/src/events/guild.rs b/src/events/guild.rs index 06af978..a677f04 100644 --- a/src/events/guild.rs +++ b/src/events/guild.rs @@ -1,7 +1,7 @@ use crate::{client::Data, storage}; use storage::settings::Settings; -use eyre::Result; +use anyhow::Result; use log::{debug, warn}; use poise::serenity_prelude::{Guild, UnavailableGuild}; diff --git a/src/events/message.rs b/src/events/message.rs index e115eb9..6f1e441 100644 --- a/src/events/message.rs +++ b/src/events/message.rs @@ -1,6 +1,6 @@ -use crate::{client::Data, consts}; +use crate::client::Data; -use eyre::{eyre, Result}; +use anyhow::{anyhow, Result}; use log::{debug, warn}; use poise::serenity_prelude::{Context, Message}; @@ -20,7 +20,7 @@ async fn should_echo(ctx: &Context, msg: &Message, data: &Data) -> Result let gid = msg .guild_id - .ok_or_else(|| eyre!("Couldn't get GuildId from {}!", msg.id))?; + .ok_or_else(|| anyhow!("Couldn't get GuildId from {}!", msg.id))?; if let Some(storage) = &data.storage { let settings = storage.get_guild_settings(&gid).await?; @@ -36,9 +36,6 @@ async fn should_echo(ctx: &Context, msg: &Message, data: &Data) -> Result let content = &msg.content; Ok(content == "🗿" - || consts::TEAMOJIS.contains(&content.as_str()) || content.to_ascii_lowercase() == "moyai" - || content - .to_ascii_lowercase() - .contains("twitter's recommendation algorithm")) + || content.to_ascii_lowercase() == "twitter's recommendation algorithm") } diff --git a/src/events/mod.rs b/src/events/mod.rs index 390c3a8..5b4c88d 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -1,6 +1,6 @@ use crate::{client::Data, consts}; -use eyre::Result; +use anyhow::Result; use log::{debug, info}; use poise::serenity_prelude::{self as serenity, CreateBotAuthParameters}; use serenity::FullEvent; diff --git a/src/events/pinboard.rs b/src/events/pinboard.rs index bb0dfe0..e1a092e 100644 --- a/src/events/pinboard.rs +++ b/src/events/pinboard.rs @@ -1,6 +1,6 @@ use crate::{client::Data, utils}; -use eyre::{eyre, Context as _, OptionExt as _, Result}; +use anyhow::{anyhow, Context as _, Result}; use log::{debug, warn}; use poise::serenity_prelude::{ ChannelId, Context, CreateAllowedMentions, CreateMessage, Message, MessageType, User, @@ -43,20 +43,20 @@ pub async fn handle(ctx: &Context, message: &Message, data: &Data) -> Result<()> let reference_id = message .clone() .message_reference - .ok_or_eyre("Couldn't get referenced message of pin!")? + .context("Couldn't get referenced message of pin!")? .message_id - .ok_or_eyre("Couldn't get id of referenced message of pin!")?; + .context("Couldn't get id of referenced message of pin!")?; let pins = message .channel_id .pins(ctx) .await - .wrap_err("Couldn't get a list of pins!?")?; + .context("Couldn't get a list of pins!?")?; let pin = pins .iter() .find(|pin| pin.id == reference_id) - .ok_or_else(|| eyre!("Couldn't find a pin for message {reference_id}!"))?; + .ok_or_else(|| anyhow!("Couldn't find a pin for message {reference_id}!"))?; redirect(ctx, pin, &message.author, &target).await?; pin.unpin(ctx).await?; @@ -75,7 +75,7 @@ async fn redirect(ctx: &Context, pin: &Message, pinner: &User, target: &ChannelI target .send_message(&ctx.http, message) .await - .wrap_err("Couldn't redirect message")?; + .context("Couldn't redirect message")?; Ok(()) } diff --git a/src/events/reactboard.rs b/src/events/reactboard.rs index c27bd80..fc806ac 100644 --- a/src/events/reactboard.rs +++ b/src/events/reactboard.rs @@ -1,7 +1,7 @@ use crate::{client::Data, storage, utils}; use storage::reactboard::ReactBoardEntry; -use eyre::{eyre, Context as _, Result}; +use anyhow::{Context as _, Result}; use log::{debug, warn}; use poise::serenity_prelude::{ Context, CreateMessage, EditMessage, GuildId, Message, MessageReaction, Reaction, @@ -12,15 +12,15 @@ pub async fn handle(ctx: &Context, reaction: &Reaction, data: &Data) -> Result<( let msg = reaction .message(&ctx.http) .await - .wrap_err("Couldn't get reaction from message!")?; + .context("Couldn't get reaction from message!")?; let matched = msg .clone() .reactions .into_iter() .find(|r| r.reaction_type == reaction.emoji) - .ok_or_else(|| { - eyre!( + .with_context(|| { + format!( "Couldn't find any matching reactions for {} in message {}!", reaction.emoji.as_data(), msg.id @@ -109,7 +109,7 @@ async fn send_to_reactboard( ctx.http .get_message(entry.posted_channel_id, entry.posted_message_id) .await - .wrap_err_with(|| { + .with_context(|| { format!( "Couldn't get previous message from ReactBoardEntry {} in Redis DB!", entry.original_message_id diff --git a/src/http/mod.rs b/src/http/mod.rs index 0f16852..dde769c 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -1,4 +1,4 @@ -use eyre::Result; +use anyhow::Result; use log::trace; use serde::de::DeserializeOwned; @@ -19,7 +19,7 @@ impl Ext for Client { fn default() -> Self { reqwest::ClientBuilder::new() .user_agent(format!( - "teawie-bot/{}", + "chill-discord-bot/{}", option_env!("CARGO_PKG_VERSION").unwrap_or("development") )) .build() diff --git a/src/http/shiggy.rs b/src/http/shiggy.rs index 397d397..a0af0b3 100644 --- a/src/http/shiggy.rs +++ b/src/http/shiggy.rs @@ -1,4 +1,4 @@ -use eyre::Result; +use anyhow::Result; use serde::Deserialize; const SHIGGY: &str = "https://safebooru.donmai.us"; diff --git a/src/http/teawie.rs b/src/http/teawie.rs index 368fad5..cd83ca2 100644 --- a/src/http/teawie.rs +++ b/src/http/teawie.rs @@ -1,4 +1,4 @@ -use eyre::{bail, OptionExt, Result}; +use anyhow::{bail, Context, Result}; use serde::{Deserialize, Serialize}; // https://github.com/getchoo/teawieAPI @@ -24,5 +24,5 @@ where }; json.url - .ok_or_eyre("TeawieAPI didn't return an error or URL???") + .context("TeawieAPI didn't return an error or URL???") } diff --git a/src/main.rs b/src/main.rs index e91c8e6..2d4bd0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ mod http; mod storage; mod utils; -use eyre::{Report, Result}; +use anyhow::Result; use tokio::signal::ctrl_c; #[cfg(target_family = "unix")] @@ -17,7 +17,6 @@ use tokio::signal::windows::ctrl_close; #[tokio::main] async fn main() -> Result<()> { dotenvy::dotenv().ok(); - color_eyre::install()?; env_logger::init(); let mut client = client::get().await?; @@ -29,7 +28,7 @@ async fn main() -> Result<()> { let mut sigterm = ctrl_close()?; tokio::select! { - result = client.start() => result.map_err(Report::from), + result = client.start() => result.map_err(anyhow::Error::from), _ = sigterm.recv() => { client::handle_shutdown(shard_manager, "Received SIGTERM").await; println!("Everything is shutdown. Goodbye!"); diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 45c150a..b025de9 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -1,9 +1,9 @@ use std::{env, fmt::Debug, str::FromStr}; -use eyre::Result; +use anyhow::Result; use log::debug; use poise::serenity_prelude::{GuildId, MessageId}; -use redis::{AsyncCommands, Client, ConnectionLike, RedisError}; +use redis::{AsyncCommands, Client, RedisError}; pub mod reactboard; pub mod settings; @@ -30,10 +30,6 @@ impl Storage { Ok(Self::from_str(&redis_url)?) } - pub fn is_connected(&mut self) -> bool { - self.client.check_connection() - } - pub async fn create_guild_settings(&self, settings: Settings) -> Result<()> { let guild_key = format!("{SETTINGS_KEY}:{}", settings.guild_id); @@ -41,7 +37,7 @@ impl Storage { redis::pipe() .set(&guild_key, &settings) .sadd(SETTINGS_KEY, u64::from(settings.guild_id)) - .query_async(&mut con) + .exec_async(&mut con) .await?; Ok(()) @@ -65,7 +61,7 @@ impl Storage { redis::pipe() .del(&guild_key) .srem(SETTINGS_KEY, u64::from(*guild_id)) - .query_async(&mut con) + .exec_async(&mut con) .await?; Ok(()) @@ -81,34 +77,6 @@ impl Storage { Ok(exists) } - pub async fn get_all_guild_settings(&self) -> Result> { - debug!("Fetching all guild settings"); - - let mut con = self.client.get_multiplexed_async_connection().await?; - let found: Vec = con.smembers(SETTINGS_KEY).await?; - - let mut guilds = vec![]; - for key in found { - let settings = self.get_guild_settings(&key.into()).await?; - guilds.push(settings); - } - - Ok(guilds) - } - - /// get guilds that have enabled optional commands - pub async fn get_opted_guilds(&self) -> Result> { - debug!("Fetching opted-in guilds"); - - let guilds = self.get_all_guild_settings().await?; - let opted: Vec = guilds - .iter() - .filter_map(|g| g.optional_commands_enabled.then_some(g.guild_id)) - .collect(); - - Ok(opted) - } - // reactboard pub async fn create_reactboard_entry( @@ -123,7 +91,9 @@ impl Storage { let entry_key = format!("{REACTBOARD_KEY}:{guild_id}:{}", entry.original_message_id); let mut con = self.client.get_multiplexed_async_connection().await?; - con.set_ex(&entry_key, &entry, 30 * 24 * 60 * 60).await?; // 30 days + // https://github.com/redis-rs/redis-rs/issues/1228 + con.set_ex::<_, _, ()>(&entry_key, &entry, 30 * 24 * 60 * 60) + .await?; // 30 days Ok(()) } diff --git a/src/utils.rs b/src/utils.rs index 3cab8c3..0166a88 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ use crate::{client::Context, consts::Colors}; -use color_eyre::eyre::{eyre, Result}; +use anyhow::{Context as _, Result}; use poise::serenity_prelude::{self as serenity, CreateEmbedAuthor, CreateEmbedFooter}; use poise::CreateReply; use rand::seq::SliceRandom; @@ -14,7 +14,7 @@ pub fn random_choice(arr: [&str; N]) -> Result { let mut rng = rand::thread_rng(); let resp = arr .choose(&mut rng) - .ok_or_else(|| eyre!("Couldn't choose random object from array:\n{arr:#?}!"))?; + .with_context(|| format!("Couldn't choose random object from array:\n{arr:#?}!"))?; Ok((*resp).to_string()) } diff --git a/treefmt.nix b/treefmt.nix deleted file mode 100644 index 81102bc..0000000 --- a/treefmt.nix +++ /dev/null @@ -1,11 +0,0 @@ -{ - projectRootFile = ".git/config"; - - programs = { - actionlint.enable = true; - deadnix.enable = true; - nixfmt.enable = true; - rustfmt.enable = true; - statix.enable = true; - }; -}