25 Commits

Author SHA1 Message Date
175de4ade9 Update debian:bullseye-slim Docker digest to fdd7556
Some checks failed
tests / fmt (push) Successful in 1m32s
tests / build (push) Successful in 1m30s
tests / clippy (push) Failing after 1m28s
tests / test (push) Successful in 1m33s
tests / pre-commit (push) Successful in 2m24s
2025-04-30 00:00:53 +00:00
de4260dd84 Update renovatebot/github-action action to v41.0.18
All checks were successful
tests / fmt (push) Successful in 42s
tests / build (push) Successful in 1m6s
tests / test (push) Successful in 2m18s
tests / clippy (push) Successful in 59s
tests / pre-commit (push) Successful in 1m0s
deploy / release-image (push) Successful in 1m3s
renovate / renovate (push) Successful in 1m29s
2025-04-01 00:01:28 +00:00
335626312b Update renovatebot/github-action action to v41.0.17
All checks were successful
tests / fmt (push) Successful in 50s
tests / build (push) Successful in 2m23s
tests / test (push) Successful in 1m29s
tests / clippy (push) Successful in 1m22s
tests / pre-commit (push) Successful in 1m5s
deploy / release-image (push) Successful in 9m20s
renovate / renovate (push) Successful in 31s
2025-03-28 00:01:48 +00:00
07a4da73c1 Update actions/setup-python digest to 8d9ed9a
All checks were successful
tests / fmt (push) Successful in 49s
tests / clippy (push) Successful in 54s
tests / test (push) Successful in 1m8s
tests / pre-commit (push) Successful in 43s
deploy / release-image (push) Successful in 43s
tests / build (push) Successful in 2m38s
renovate / renovate (push) Successful in 1m50s
2025-03-27 00:01:24 +00:00
fa1d720d0f Update dependency python to 3.13
All checks were successful
tests / build (push) Successful in 55s
tests / fmt (push) Successful in 1m4s
tests / test (push) Successful in 1m25s
deploy / release-image (push) Successful in 48s
tests / clippy (push) Successful in 2m13s
tests / pre-commit (push) Successful in 3m5s
renovate / renovate (push) Successful in 59s
2025-03-26 00:02:13 +00:00
1ec358ec8f Update Rust crate uuid to v1.16.0
All checks were successful
tests / fmt (push) Successful in 1m17s
tests / clippy (push) Successful in 1m11s
tests / build (push) Successful in 1m18s
tests / test (push) Successful in 1m25s
tests / pre-commit (push) Successful in 1m29s
deploy / release-image (push) Successful in 2m14s
renovate / renovate (push) Successful in 1m12s
2025-03-22 00:01:47 +00:00
624e08f3aa Update Rust crate reqwest to v0.12.15
All checks were successful
tests / fmt (push) Successful in 56s
tests / build (push) Successful in 1m52s
tests / pre-commit (push) Successful in 1m24s
tests / test (push) Successful in 1m42s
tests / clippy (push) Successful in 4m59s
deploy / release-image (push) Successful in 3m54s
renovate / renovate (push) Successful in 1m20s
2025-03-22 01:01:27 +01:00
f4f6a486c9 Update debian:bullseye-slim Docker digest to e4b93db
Some checks are pending
tests / fmt (push) Waiting to run
tests / build (push) Waiting to run
tests / test (push) Waiting to run
tests / clippy (push) Waiting to run
tests / pre-commit (push) Waiting to run
deploy / release-image (push) Waiting to run
renovate / renovate (push) Waiting to run
2025-03-21 00:01:10 +00:00
c354ec0562 Update rust:slim-bullseye Docker digest to 1eca9af
All checks were successful
tests / build (push) Successful in 59s
tests / fmt (push) Successful in 1m8s
tests / test (push) Successful in 1m14s
tests / clippy (push) Successful in 55s
tests / pre-commit (push) Successful in 2m6s
deploy / release-image (push) Successful in 3m31s
renovate / renovate (push) Successful in 1m30s
2025-03-20 00:00:51 +00:00
e0f1abcd9c Update renovatebot/github-action action to v41.0.16
Some checks failed
tests / fmt (push) Successful in 3m27s
tests / clippy (push) Successful in 1m50s
tests / pre-commit (push) Successful in 1m20s
deploy / release-image (push) Failing after 40s
renovate / renovate (push) Failing after 2m50s
tests / test (push) Successful in 5m3s
tests / build (push) Successful in 7m38s
2025-03-18 00:00:51 +00:00
aa302e4bb5 Update Rust crate reqwest to v0.12.14
All checks were successful
tests / fmt (push) Successful in 1m0s
tests / clippy (push) Successful in 1m9s
tests / pre-commit (push) Successful in 46s
tests / test (push) Successful in 1m34s
renovate / renovate (push) Successful in 27s
tests / build (push) Successful in 3m44s
deploy / release-image (push) Successful in 2m29s
2025-03-17 00:04:53 +00:00
c461671bfb Update Rust crate serde to v1.0.219
All checks were successful
tests / fmt (push) Successful in 1m31s
tests / test (push) Successful in 1m55s
tests / build (push) Successful in 1m59s
tests / pre-commit (push) Successful in 1m5s
deploy / release-image (push) Successful in 2m6s
tests / clippy (push) Successful in 5m1s
renovate / renovate (push) Successful in 1m18s
2025-03-17 01:02:17 +01:00
271ec4d323 Update Rust crate async-trait to v0.1.88
Some checks failed
tests / clippy (push) Waiting to run
tests / pre-commit (push) Waiting to run
deploy / release-image (push) Waiting to run
renovate / renovate (push) Waiting to run
tests / build (push) Has been cancelled
tests / fmt (push) Has been cancelled
tests / test (push) Has been cancelled
2025-03-16 00:01:16 +00:00
1e807c121d Update docker/login-action digest to 74a5d14
Some checks failed
tests / fmt (push) Successful in 56s
tests / clippy (push) Successful in 1m58s
tests / pre-commit (push) Successful in 1m57s
tests / build (push) Successful in 2m57s
renovate / renovate (push) Successful in 1m3s
tests / test (push) Failing after 6m22s
deploy / release-image (push) Successful in 5m54s
2025-03-15 00:02:19 +00:00
4293775824 Update Rust crate tokio to v1.44.1
Some checks failed
tests / fmt (push) Successful in 1m2s
tests / build (push) Successful in 5m2s
tests / test (push) Failing after 5m11s
tests / clippy (push) Successful in 2m39s
tests / pre-commit (push) Successful in 2m45s
deploy / release-image (push) Successful in 6m57s
renovate / renovate (push) Successful in 28s
2025-03-13 14:11:29 +00:00
fa8f5f5b04 Update rust:slim-bullseye Docker digest to 7fe28fe
All checks were successful
tests / fmt (push) Successful in 1m32s
tests / build (push) Successful in 2m6s
tests / clippy (push) Successful in 1m37s
tests / test (push) Successful in 1m57s
tests / pre-commit (push) Successful in 1m36s
deploy / release-image (push) Successful in 3m12s
renovate / renovate (push) Successful in 2m14s
2025-03-07 23:29:12 +00:00
4ecf9bf205 Update Rust crate tokio to v1.44.0
All checks were successful
tests / fmt (push) Successful in 1m16s
tests / build (push) Successful in 1m40s
tests / test (push) Successful in 1m46s
tests / clippy (push) Successful in 1m15s
tests / pre-commit (push) Successful in 3m12s
deploy / release-image (push) Successful in 6m36s
renovate / renovate (push) Successful in 17s
2025-03-07 23:15:39 +00:00
5b5ca52c04 enable docker cache
All checks were successful
tests / fmt (push) Successful in 1m14s
tests / clippy (push) Successful in 1m27s
tests / build (push) Successful in 1m34s
tests / test (push) Successful in 1m45s
tests / pre-commit (push) Successful in 3m53s
deploy / release-image (push) Successful in 3m44s
renovate / renovate (push) Successful in 28s
2025-03-05 03:54:53 +01:00
ebb66e21cc use Track::new_with_data
Some checks failed
tests / fmt (push) Successful in 1m31s
tests / clippy (push) Successful in 1m42s
tests / pre-commit (push) Successful in 1m42s
tests / test (push) Successful in 1m55s
tests / build (push) Successful in 1m58s
renovate / renovate (push) Successful in 27s
deploy / release-image (push) Has been cancelled
2025-03-05 03:51:02 +01:00
f240b8f0f6 Merge pull request 'Update docker/build-push-action action to v6' (#31) from renovate/docker-build-push-action-6.x into main
All checks were successful
tests / fmt (push) Successful in 1m37s
tests / clippy (push) Successful in 1m34s
tests / pre-commit (push) Successful in 1m32s
tests / test (push) Successful in 1m45s
renovate / renovate (push) Successful in 26s
deploy / release-image (push) Successful in 3m4s
tests / build (push) Successful in 5m52s
Reviewed-on: #31
2025-03-05 03:37:47 +01:00
65c09c5e85 Merge pull request 'Update Rust crate tracing-subscriber to 0.3' (#23) from renovate/tokio-tracing-monorepo into main
Some checks failed
tests / pre-commit (push) Waiting to run
deploy / release-image (push) Waiting to run
renovate / renovate (push) Waiting to run
tests / clippy (push) Has been cancelled
tests / test (push) Has been cancelled
tests / fmt (push) Has been cancelled
tests / build (push) Has been cancelled
Reviewed-on: #23
2025-03-05 03:37:41 +01:00
c9837e456e Update docker/build-push-action action to v6
All checks were successful
tests / fmt (push) Successful in 57s
tests / clippy (push) Successful in 1m43s
tests / build (push) Successful in 1m55s
tests / pre-commit (push) Successful in 1m42s
tests / test (push) Successful in 2m7s
2025-03-05 02:31:29 +00:00
9efc372f8f Update Rust crate tracing-subscriber to 0.3
All checks were successful
tests / fmt (push) Successful in 1m39s
tests / test (push) Successful in 1m45s
tests / clippy (push) Successful in 1m22s
tests / pre-commit (push) Successful in 1m11s
tests / build (push) Successful in 51s
2025-03-05 02:31:24 +00:00
7ff991206b Merge branch 'main' of gitea:jheuel/ohrwurm
All checks were successful
tests / fmt (push) Successful in 1m26s
tests / clippy (push) Successful in 1m22s
tests / pre-commit (push) Successful in 1m29s
tests / test (push) Successful in 1m40s
renovate / renovate (push) Successful in 1m10s
tests / build (push) Successful in 2m28s
deploy / release-image (push) Successful in 4m13s
2025-03-05 03:28:57 +01:00
b1d6069d81 update twilight, songbird and reqwest 2025-03-05 03:27:43 +01:00
15 changed files with 966 additions and 440 deletions

View File

@@ -38,9 +38,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo apt-get update
- run: sudo apt-get install -y cmake
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
with:
python-version: '3.12'
python-version: '3.13'
- name: Install yt-dlp
run: pip install yt-dlp
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
@@ -65,9 +65,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo apt-get update
- run: sudo apt-get install -y cmake
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
with:
python-version: '3.12'
python-version: '3.13'
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
with:
components: rustfmt

View File

@@ -19,15 +19,17 @@ jobs:
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
- name: Login to DockerHub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
with:
platforms: |
linux/amd64
push: true
tags: jheuel/ohrwurm:latest
cache-from: type=gha
cache-to: type=gha,mode=max

View File

@@ -17,7 +17,7 @@ jobs:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Self-hosted Renovate
uses: renovatebot/github-action@02f4fdeb479bbb229caa7ad82cb5e691c07e80b3 # v41.0.14
uses: renovatebot/github-action@c21017a4a2fc9f42953bcc907e375a5a544557ec # v41.0.18
with:
token: ${{ secrets.RENOVATE_TOKEN }}
env-regex: "^(?:RENOVATE_\\w+|LOG_LEVEL|GITHUB_COM_TOKEN)$"

View File

@@ -37,9 +37,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo apt-get update
- run: sudo apt-get install -y cmake
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
with:
python-version: '3.12'
python-version: '3.13'
- name: Install yt-dlp
run: pip install yt-dlp
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
@@ -64,9 +64,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo apt-get update
- run: sudo apt-get install -y cmake
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
with:
python-version: '3.12'
python-version: '3.13'
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
with:
components: rustfmt

1141
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,20 +7,20 @@ license = "MIT"
[dependencies]
symphonia = { version = "0.5.2", features=["all", "opt-simd"] }
songbird = { version = "0.4.0", features = ["driver", "gateway", "twilight", "rustls", "builtin-queue"] }
songbird = { version = "0.5.0", features = ["driver", "gateway", "twilight", "rustls", "builtin-queue"] }
tokio = { features = ["macros", "rt-multi-thread", "signal", "sync"], version = "1" }
sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate"] }
regex = { version = "1", features = ["unicode-case"] }
futures = "0.3"
reqwest = "0.11"
reqwest = "0.12"
tracing = "0.1"
tracing-subscriber = "0.2"
twilight-gateway = "0.15"
twilight-http = "0.15"
twilight-model = "0.15"
twilight-standby = "0.15"
twilight-cache-inmemory = "0.15"
twilight-util = { version = "0.15", features=["builder"] }
tracing-subscriber = "0.3"
twilight-gateway = "0.16"
twilight-http = "0.16"
twilight-model = "0.16"
twilight-standby = "0.16"
twilight-cache-inmemory = "0.16"
twilight-util = { version = "0.16", features=["builder"] }
dotenv = "0.15.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@@ -1,5 +1,5 @@
# Build image
FROM rust:slim-bullseye@sha256:e94e2d2e0a9df48fdfcacb47d8b60d036abe60b7c6fa3ac3de1dd16a3d18f19a as build
FROM rust:slim-bullseye@sha256:1eca9af45f393ac4669b9b63659529638359575f6268cbd4e6543ddc46c53803 as build
RUN apt-get update && apt-get install -y \
build-essential autoconf automake cmake libtool libssl-dev pkg-config
@@ -18,7 +18,7 @@ RUN touch src/main.rs
RUN cargo build --release --locked
# Release image
FROM debian:bullseye-slim@sha256:33b7c2e071c29e618182ec872c471f39d2dde3d8904d95f5b7a61acf3a592e7b
FROM debian:bullseye-slim@sha256:fdd75562fdcde1039c2480a1ea1cd2cf03b18b6e4cb551cabb03bde66ade8a5d
RUN apt-get update && apt-get install -y python3-pip
RUN pip install -U yt-dlp

View File

@@ -26,7 +26,7 @@ pub(crate) async fn delete(
.http
.channel_messages(msg.channel_id)
.before(msg.id)
.limit(n)?
.limit(n)
.await?
.model()
.await?;

View File

@@ -1,6 +1,7 @@
use crate::metadata::MetadataMap;
use crate::metadata::Metadata;
use crate::state::{State, StateRef};
use async_trait::async_trait;
use songbird::tracks::Track;
use songbird::{Event, EventContext, EventHandler, TrackEvent};
use std::ops::Sub;
use std::time::Duration;
@@ -99,12 +100,11 @@ impl EventHandler for TrackEndNotifier {
let mut call = call_lock.lock().await;
// get metadata from finished track
let old_typemap_lock = track_handle.typemap().read().await;
let old_metadata = old_typemap_lock.get::<MetadataMap>().unwrap();
let old_metadata = track_handle.data::<Metadata>();
// enqueue track
let handle = call.enqueue_with_preload(
old_metadata.src.clone().into(),
let track = Track::new_with_data(old_metadata.src.clone().into(), old_metadata.clone());
let _handle = call.enqueue_with_preload(
track,
old_metadata.duration.map(|duration| -> Duration {
if duration.as_secs() > 5 {
duration.sub(Duration::from_secs(5))
@@ -113,10 +113,6 @@ impl EventHandler for TrackEndNotifier {
}
}),
);
// insert metadata into new track
let mut new_typemap = handle.typemap().write().await;
new_typemap.insert::<MetadataMap>(old_metadata.clone());
}
None
}

View File

@@ -1,5 +1,5 @@
use crate::commands::join::join_channel;
use crate::metadata::{Metadata, MetadataMap};
use crate::metadata::Metadata;
use crate::state::State;
use crate::{colors, db};
@@ -266,7 +266,7 @@ pub(crate) async fn play(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await?;
Ok(())
}
@@ -348,7 +348,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await
.context("Could not send playlist loading message")?;
}
@@ -368,12 +368,21 @@ pub(crate) async fn play_inner(
.context("Could not find url")?;
let mut src = YoutubeDl::new(state.client.clone(), url.clone());
let track: Track = src.clone().into();
match src.aux_metadata().await {
Ok(metadata) => {
debug!("metadata: {:?}", metadata);
let track: Track = Track::new_with_data(
src.clone().into(),
Arc::new(Metadata {
title: metadata.title.clone(),
duration: metadata.duration,
url: url.clone(),
src,
}),
);
persistence(interaction, yttrack, Arc::clone(&state))
.await
.unwrap_or_else(|e| {
@@ -391,7 +400,7 @@ pub(crate) async fn play_inner(
match state.songbird.get(guild_id) {
Some(call_lock) => {
let mut call = call_lock.lock().await;
let handle = call.enqueue_with_preload(
let _handle = call.enqueue_with_preload(
track,
metadata.duration.map(|duration| -> Duration {
if duration.as_secs() > 5 {
@@ -401,13 +410,6 @@ pub(crate) async fn play_inner(
}
}),
);
let mut x = handle.typemap().write().await;
x.insert::<MetadataMap>(Metadata {
title: metadata.title,
duration: metadata.duration,
url,
src,
});
}
None => tracing::error!("could not get call lock"),
}
@@ -427,7 +429,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await?;
return Ok(());
}
@@ -440,7 +442,7 @@ pub(crate) async fn play_inner(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.embeds(Some(&embeds))
.await
.context("Could not send final play message")?;

View File

@@ -1,6 +1,6 @@
use songbird::tracks::TrackHandle;
use twilight_model::channel::message::component::{ActionRow, Button, ButtonStyle};
use twilight_model::channel::message::{Component, Embed, MessageFlags, ReactionType};
use twilight_model::channel::message::{Component, Embed, EmojiReactionType, MessageFlags};
use twilight_model::gateway::payload::incoming::InteractionCreate;
use twilight_model::http::interaction::InteractionResponse;
use twilight_model::http::interaction::InteractionResponseType;
@@ -8,7 +8,8 @@ use twilight_util::builder::embed::EmbedBuilder;
use twilight_util::builder::InteractionResponseDataBuilder;
use crate::colors;
use crate::{metadata::MetadataMap, state::State};
use crate::metadata::Metadata;
use crate::state::State;
use std::error::Error;
pub(crate) const TRACKS_PER_PAGE: usize = 5;
@@ -38,10 +39,7 @@ pub(crate) async fn build_queue_embeds(queue: &[TrackHandle], page: usize) -> Ve
.skip(TRACKS_PER_PAGE * page)
.take(TRACKS_PER_PAGE)
{
let map = track.typemap().read().await;
let metadata = map
.get::<MetadataMap>()
.expect("Could not get metadata map");
let metadata = track.data::<Metadata>();
message.push_str(
format!(
"* [{}]({})",
@@ -76,31 +74,34 @@ pub(crate) fn build_action_row(page: usize, n_pages: usize) -> Vec<Component> {
custom_id: Some(format!("page:{}", page as i32 - 1)),
style: ButtonStyle::Primary,
label: Some("Previous page".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "⬅️".to_string(),
}),
url: None,
disabled: page == 0,
sku_id: None,
}),
Component::Button(Button {
custom_id: Some(format!("page:{}", page)),
style: ButtonStyle::Primary,
label: Some("Refresh".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "🔄".to_string(),
}),
url: None,
disabled: false,
sku_id: None,
}),
Component::Button(Button {
custom_id: Some(format!("page:{}", page + 1)),
style: ButtonStyle::Primary,
label: Some("Next page".to_string()),
emoji: Some(ReactionType::Unicode {
emoji: Some(EmojiReactionType::Unicode {
name: "➡️".to_string(),
}),
url: None,
disabled: page >= n_pages - 1,
sku_id: None,
}),
],
})]
@@ -153,8 +154,8 @@ pub(crate) async fn queue(
.http
.interaction(interaction.application_id)
.update_response(&interaction.token)
.embeds(Some(&embeds))?
.components(Some(&action_row))?
.embeds(Some(&embeds))
.components(Some(&action_row))
.await?;
Ok(())

View File

@@ -14,6 +14,7 @@ use twilight_model::gateway::payload::incoming::InteractionCreate;
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
use twilight_util::builder::InteractionResponseDataBuilder;
#[derive(Debug, Clone)]
pub(crate) struct Handler {
state: State,
}

View File

@@ -12,18 +12,12 @@ mod utils;
use crate::commands::get_chat_commands;
use dotenv::dotenv;
use futures::StreamExt;
use signal::signal_handler;
use songbird::{shards::TwilightMap, Songbird};
use state::StateRef;
use std::{env, error::Error, str::FromStr, sync::Arc, time::Duration};
use tokio::select;
use tracing::{debug, info};
use twilight_cache_inmemory::InMemoryCache;
use twilight_gateway::{
stream::{self, ShardEventStream},
Intents, Shard,
};
use twilight_gateway::{Event, EventTypeFlags, Intents, Shard, StreamExt as _};
use twilight_http::Client as HttpClient;
use twilight_model::id::Id;
use twilight_standby::Standby;
@@ -38,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
info!("Starting up...");
let (mut shards, state) = {
let (shards, state) = {
let db = env::var("DATABASE_URL").map_err(|_| "DATABASE_URL is not set")?;
let options = SqliteConnectOptions::from_str(&db)
.expect("could not create options")
@@ -71,7 +65,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
| Intents::MESSAGE_CONTENT;
let config = twilight_gateway::Config::new(token.clone(), intents);
let shards: Vec<Shard> =
stream::create_recommended(&http, config, |_, builder| builder.build())
twilight_gateway::create_recommended(&http, config, |_, builder| builder.build())
.await?
.collect();
let senders = TwilightMap::new(
@@ -105,45 +99,55 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
info!("Ready to receive events");
let handler = Handler::new(Arc::clone(&state));
let mut stop_rx = signal_handler();
let mut stream = ShardEventStream::new(shards.iter_mut());
loop {
select! {
biased;
_ = stop_rx.changed() => {
for guild in state.cache.iter().guilds() {
if let Some(user) = state.cache.current_user() {
if state.cache.voice_state(user.id, guild.id()).is_some() {
debug!("Leaving guild {:?}", guild.id());
state.songbird.leave(guild.id()).await?;
}
}
}
// need to grab next event to properly leave voice channels
stream.next().await;
break;
},
next = stream.next() => {
let event = match next {
Some((_, Ok(event))) => event,
Some((_, Err(source))) => {
tracing::warn!(?source, "error receiving event");
if source.is_fatal() {
break;
}
continue;
}
None => break,
};
debug!("Event: {:?}", &event);
// let mut stop_rx = signal_handler();
let mut set = tokio::task::JoinSet::new();
state.cache.update(&event);
state.standby.process(&event);
state.songbird.process(&event).await;
handler.act(event).await?;
}
}
for shard in shards {
set.spawn(tokio::spawn(runner(shard, handler.clone(), state.clone())));
}
set.join_next().await;
Ok(())
}
async fn runner(mut shard: Shard, handler: Handler, state: Arc<StateRef>) {
while let Some(item) = shard.next_event(EventTypeFlags::all()).await {
let event = match item {
Ok(event) => event,
Err(source) => {
tracing::warn!(?source, "error receiving event");
continue;
}
};
tokio::spawn({
let state = state.clone();
let handler = handler.clone();
async move {
handle_event(event, handler, state)
.await
.unwrap_or_else(|source| {
tracing::warn!(?source, "error handling event");
});
}
});
}
}
async fn handle_event(
event: Event,
handler: Handler,
state: Arc<StateRef>,
) -> Result<(), Box<dyn Error>> {
state.standby.process(&event);
state.songbird.process(&event).await;
debug!("Event: {:?}", &event);
state.cache.update(&event);
state.standby.process(&event);
state.songbird.process(&event).await;
handler.act(event).await?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use songbird::{input::YoutubeDl, typemap::TypeMapKey};
use songbird::input::YoutubeDl;
use std::time::Duration;
#[derive(Clone)]
@@ -6,10 +6,5 @@ pub(crate) struct Metadata {
pub(crate) title: Option<String>,
pub(crate) duration: Option<Duration>,
pub(crate) url: String,
pub(crate) src: YoutubeDl,
}
pub(crate) struct MetadataMap;
impl TypeMapKey for MetadataMap {
type Value = Metadata;
pub(crate) src: YoutubeDl<'static>,
}

View File

@@ -1,21 +1,21 @@
use tokio::{
select,
signal::unix::{signal, SignalKind},
sync::watch,
};
// use tokio::{
// select,
// signal::unix::{signal, SignalKind},
// sync::watch,
// };
pub(crate) fn signal_handler() -> watch::Receiver<()> {
let (stop_tx, stop_rx) = watch::channel(());
tokio::spawn(async move {
let mut sigterm = signal(SignalKind::terminate()).unwrap();
let mut sigint = signal(SignalKind::interrupt()).unwrap();
loop {
select! {
_ = sigterm.recv() => println!("Receive SIGTERM"),
_ = sigint.recv() => println!("Receive SIGTERM"),
};
stop_tx.send(()).unwrap();
}
});
stop_rx
}
// pub(crate) fn signal_handler() -> watch::Receiver<()> {
// let (stop_tx, stop_rx) = watch::channel(());
// tokio::spawn(async move {
// let mut sigterm = signal(SignalKind::terminate()).unwrap();
// let mut sigint = signal(SignalKind::interrupt()).unwrap();
// loop {
// select! {
// _ = sigterm.recv() => println!("Receive SIGTERM"),
// _ = sigint.recv() => println!("Receive SIGTERM"),
// };
// stop_tx.send(()).unwrap();
// }
// });
// stop_rx
// }