Compare commits
31 Commits
897d4f2860
...
renovate/d
| Author | SHA1 | Date | |
|---|---|---|---|
| 175de4ade9 | |||
| de4260dd84 | |||
| 335626312b | |||
| 07a4da73c1 | |||
| fa1d720d0f | |||
| 1ec358ec8f | |||
| 624e08f3aa | |||
| f4f6a486c9 | |||
| c354ec0562 | |||
| e0f1abcd9c | |||
| aa302e4bb5 | |||
| c461671bfb | |||
| 271ec4d323 | |||
| 1e807c121d | |||
| 4293775824 | |||
| fa8f5f5b04 | |||
| 4ecf9bf205 | |||
|
5b5ca52c04
|
|||
|
ebb66e21cc
|
|||
| f240b8f0f6 | |||
| 65c09c5e85 | |||
| c9837e456e | |||
| 9efc372f8f | |||
|
7ff991206b
|
|||
|
b1d6069d81
|
|||
| de3262c072 | |||
| 8e88cadbb8 | |||
|
c6e34cf000
|
|||
| 3b135894eb | |||
| 14cab9d833 | |||
|
f2f4396674
|
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)$"
|
||||
|
||||
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@@ -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
|
||||
|
||||
1602
Cargo.lock
generated
1602
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
18
Cargo.toml
18
Cargo.toml
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
services:
|
||||
ohrwurm:
|
||||
container_name: ohrwurm
|
||||
image: jheuel/ohrwurm:latest@sha256:b5e0fbc40ed86820eba8673bb5a97ad6ce53f27a1c557e46515cabce35199296
|
||||
# build: .
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- ./data:/data
|
||||
env_file:
|
||||
- .env
|
||||
@@ -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?;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")?;
|
||||
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
98
src/main.rs
98
src/main.rs
@@ -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(())
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user