Compare commits
31 Commits
897d4f2860
...
renovate/t
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d33e74432 | |||
| 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
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
- run: sudo apt-get update
|
- run: sudo apt-get update
|
||||||
- run: sudo apt-get install -y cmake
|
- run: sudo apt-get install -y cmake
|
||||||
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.13'
|
||||||
- name: Install yt-dlp
|
- name: Install yt-dlp
|
||||||
run: pip install yt-dlp
|
run: pip install yt-dlp
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
||||||
@@ -65,9 +65,9 @@ jobs:
|
|||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
- run: sudo apt-get update
|
- run: sudo apt-get update
|
||||||
- run: sudo apt-get install -y cmake
|
- run: sudo apt-get install -y cmake
|
||||||
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.13'
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
||||||
with:
|
with:
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
|
|||||||
@@ -19,15 +19,17 @@ jobs:
|
|||||||
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
|
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
|
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5
|
uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 # v6
|
||||||
with:
|
with:
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: jheuel/ohrwurm:latest
|
tags: jheuel/ohrwurm:latest
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: Self-hosted Renovate
|
- name: Self-hosted Renovate
|
||||||
uses: renovatebot/github-action@02f4fdeb479bbb229caa7ad82cb5e691c07e80b3 # v41.0.14
|
uses: renovatebot/github-action@c21017a4a2fc9f42953bcc907e375a5a544557ec # v41.0.18
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.RENOVATE_TOKEN }}
|
token: ${{ secrets.RENOVATE_TOKEN }}
|
||||||
env-regex: "^(?:RENOVATE_\\w+|LOG_LEVEL|GITHUB_COM_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
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
- run: sudo apt-get update
|
- run: sudo apt-get update
|
||||||
- run: sudo apt-get install -y cmake
|
- run: sudo apt-get install -y cmake
|
||||||
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.13'
|
||||||
- name: Install yt-dlp
|
- name: Install yt-dlp
|
||||||
run: pip install yt-dlp
|
run: pip install yt-dlp
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
||||||
@@ -64,9 +64,9 @@ jobs:
|
|||||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
|
||||||
- run: sudo apt-get update
|
- run: sudo apt-get update
|
||||||
- run: sudo apt-get install -y cmake
|
- run: sudo apt-get install -y cmake
|
||||||
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
|
- uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.12'
|
python-version: '3.13'
|
||||||
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
- uses: actions-rust-lang/setup-rust-toolchain@9399c7bb15d4c7d47b27263d024f0a4978346ba4 # v1
|
||||||
with:
|
with:
|
||||||
components: rustfmt
|
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]
|
[dependencies]
|
||||||
symphonia = { version = "0.5.2", features=["all", "opt-simd"] }
|
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" }
|
tokio = { features = ["macros", "rt-multi-thread", "signal", "sync"], version = "1" }
|
||||||
sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate"] }
|
sqlx = { version = "0.8", features = [ "runtime-tokio", "sqlite", "chrono", "migrate"] }
|
||||||
regex = { version = "1", features = ["unicode-case"] }
|
regex = { version = "1", features = ["unicode-case"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
reqwest = "0.11"
|
reqwest = "0.12"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.2"
|
tracing-subscriber = "0.3"
|
||||||
twilight-gateway = "0.15"
|
twilight-gateway = "0.16"
|
||||||
twilight-http = "0.15"
|
twilight-http = "0.16"
|
||||||
twilight-model = "0.15"
|
twilight-model = "0.16"
|
||||||
twilight-standby = "0.15"
|
twilight-standby = "0.16"
|
||||||
twilight-cache-inmemory = "0.15"
|
twilight-cache-inmemory = "0.16"
|
||||||
twilight-util = { version = "0.15", features=["builder"] }
|
twilight-util = { version = "0.16", features=["builder"] }
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Build image
|
# 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 \
|
RUN apt-get update && apt-get install -y \
|
||||||
build-essential autoconf automake cmake libtool libssl-dev pkg-config
|
build-essential autoconf automake cmake libtool libssl-dev pkg-config
|
||||||
@@ -18,7 +18,7 @@ RUN touch src/main.rs
|
|||||||
RUN cargo build --release --locked
|
RUN cargo build --release --locked
|
||||||
|
|
||||||
# Release image
|
# Release image
|
||||||
FROM debian:bullseye-slim@sha256:33b7c2e071c29e618182ec872c471f39d2dde3d8904d95f5b7a61acf3a592e7b
|
FROM debian:bullseye-slim@sha256:e4b93db6aad977a95aa103917f3de8a2b16ead91cf255c3ccdb300c5d20f3015
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y python3-pip
|
RUN apt-get update && apt-get install -y python3-pip
|
||||||
RUN pip install -U yt-dlp
|
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
|
.http
|
||||||
.channel_messages(msg.channel_id)
|
.channel_messages(msg.channel_id)
|
||||||
.before(msg.id)
|
.before(msg.id)
|
||||||
.limit(n)?
|
.limit(n)
|
||||||
.await?
|
.await?
|
||||||
.model()
|
.model()
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::metadata::MetadataMap;
|
use crate::metadata::Metadata;
|
||||||
use crate::state::{State, StateRef};
|
use crate::state::{State, StateRef};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use songbird::tracks::Track;
|
||||||
use songbird::{Event, EventContext, EventHandler, TrackEvent};
|
use songbird::{Event, EventContext, EventHandler, TrackEvent};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@@ -99,12 +100,11 @@ impl EventHandler for TrackEndNotifier {
|
|||||||
let mut call = call_lock.lock().await;
|
let mut call = call_lock.lock().await;
|
||||||
|
|
||||||
// get metadata from finished track
|
// get metadata from finished track
|
||||||
let old_typemap_lock = track_handle.typemap().read().await;
|
let old_metadata = track_handle.data::<Metadata>();
|
||||||
let old_metadata = old_typemap_lock.get::<MetadataMap>().unwrap();
|
|
||||||
|
|
||||||
// enqueue track
|
// enqueue track
|
||||||
let handle = call.enqueue_with_preload(
|
let track = Track::new_with_data(old_metadata.src.clone().into(), old_metadata.clone());
|
||||||
old_metadata.src.clone().into(),
|
let _handle = call.enqueue_with_preload(
|
||||||
|
track,
|
||||||
old_metadata.duration.map(|duration| -> Duration {
|
old_metadata.duration.map(|duration| -> Duration {
|
||||||
if duration.as_secs() > 5 {
|
if duration.as_secs() > 5 {
|
||||||
duration.sub(Duration::from_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
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::commands::join::join_channel;
|
use crate::commands::join::join_channel;
|
||||||
use crate::metadata::{Metadata, MetadataMap};
|
use crate::metadata::Metadata;
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use crate::{colors, db};
|
use crate::{colors, db};
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ pub(crate) async fn play(
|
|||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.embeds(Some(&embeds))?
|
.embeds(Some(&embeds))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ pub(crate) async fn play_inner(
|
|||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.embeds(Some(&embeds))?
|
.embeds(Some(&embeds))
|
||||||
.await
|
.await
|
||||||
.context("Could not send playlist loading message")?;
|
.context("Could not send playlist loading message")?;
|
||||||
}
|
}
|
||||||
@@ -368,12 +368,21 @@ pub(crate) async fn play_inner(
|
|||||||
.context("Could not find url")?;
|
.context("Could not find url")?;
|
||||||
|
|
||||||
let mut src = YoutubeDl::new(state.client.clone(), url.clone());
|
let mut src = YoutubeDl::new(state.client.clone(), url.clone());
|
||||||
let track: Track = src.clone().into();
|
|
||||||
|
|
||||||
match src.aux_metadata().await {
|
match src.aux_metadata().await {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
debug!("metadata: {:?}", 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))
|
persistence(interaction, yttrack, Arc::clone(&state))
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
@@ -391,7 +400,7 @@ pub(crate) async fn play_inner(
|
|||||||
match state.songbird.get(guild_id) {
|
match state.songbird.get(guild_id) {
|
||||||
Some(call_lock) => {
|
Some(call_lock) => {
|
||||||
let mut call = call_lock.lock().await;
|
let mut call = call_lock.lock().await;
|
||||||
let handle = call.enqueue_with_preload(
|
let _handle = call.enqueue_with_preload(
|
||||||
track,
|
track,
|
||||||
metadata.duration.map(|duration| -> Duration {
|
metadata.duration.map(|duration| -> Duration {
|
||||||
if duration.as_secs() > 5 {
|
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"),
|
None => tracing::error!("could not get call lock"),
|
||||||
}
|
}
|
||||||
@@ -427,7 +429,7 @@ pub(crate) async fn play_inner(
|
|||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.embeds(Some(&embeds))?
|
.embeds(Some(&embeds))
|
||||||
.await?;
|
.await?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -440,7 +442,7 @@ pub(crate) async fn play_inner(
|
|||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.embeds(Some(&embeds))?
|
.embeds(Some(&embeds))
|
||||||
.await
|
.await
|
||||||
.context("Could not send final play message")?;
|
.context("Could not send final play message")?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use songbird::tracks::TrackHandle;
|
use songbird::tracks::TrackHandle;
|
||||||
use twilight_model::channel::message::component::{ActionRow, Button, ButtonStyle};
|
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::gateway::payload::incoming::InteractionCreate;
|
||||||
use twilight_model::http::interaction::InteractionResponse;
|
use twilight_model::http::interaction::InteractionResponse;
|
||||||
use twilight_model::http::interaction::InteractionResponseType;
|
use twilight_model::http::interaction::InteractionResponseType;
|
||||||
@@ -8,7 +8,8 @@ use twilight_util::builder::embed::EmbedBuilder;
|
|||||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||||
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::{metadata::MetadataMap, state::State};
|
use crate::metadata::Metadata;
|
||||||
|
use crate::state::State;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
pub(crate) const TRACKS_PER_PAGE: usize = 5;
|
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)
|
.skip(TRACKS_PER_PAGE * page)
|
||||||
.take(TRACKS_PER_PAGE)
|
.take(TRACKS_PER_PAGE)
|
||||||
{
|
{
|
||||||
let map = track.typemap().read().await;
|
let metadata = track.data::<Metadata>();
|
||||||
let metadata = map
|
|
||||||
.get::<MetadataMap>()
|
|
||||||
.expect("Could not get metadata map");
|
|
||||||
message.push_str(
|
message.push_str(
|
||||||
format!(
|
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)),
|
custom_id: Some(format!("page:{}", page as i32 - 1)),
|
||||||
style: ButtonStyle::Primary,
|
style: ButtonStyle::Primary,
|
||||||
label: Some("Previous page".to_string()),
|
label: Some("Previous page".to_string()),
|
||||||
emoji: Some(ReactionType::Unicode {
|
emoji: Some(EmojiReactionType::Unicode {
|
||||||
name: "⬅️".to_string(),
|
name: "⬅️".to_string(),
|
||||||
}),
|
}),
|
||||||
url: None,
|
url: None,
|
||||||
disabled: page == 0,
|
disabled: page == 0,
|
||||||
|
sku_id: None,
|
||||||
}),
|
}),
|
||||||
Component::Button(Button {
|
Component::Button(Button {
|
||||||
custom_id: Some(format!("page:{}", page)),
|
custom_id: Some(format!("page:{}", page)),
|
||||||
style: ButtonStyle::Primary,
|
style: ButtonStyle::Primary,
|
||||||
label: Some("Refresh".to_string()),
|
label: Some("Refresh".to_string()),
|
||||||
emoji: Some(ReactionType::Unicode {
|
emoji: Some(EmojiReactionType::Unicode {
|
||||||
name: "🔄".to_string(),
|
name: "🔄".to_string(),
|
||||||
}),
|
}),
|
||||||
url: None,
|
url: None,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
sku_id: None,
|
||||||
}),
|
}),
|
||||||
Component::Button(Button {
|
Component::Button(Button {
|
||||||
custom_id: Some(format!("page:{}", page + 1)),
|
custom_id: Some(format!("page:{}", page + 1)),
|
||||||
style: ButtonStyle::Primary,
|
style: ButtonStyle::Primary,
|
||||||
label: Some("Next page".to_string()),
|
label: Some("Next page".to_string()),
|
||||||
emoji: Some(ReactionType::Unicode {
|
emoji: Some(EmojiReactionType::Unicode {
|
||||||
name: "➡️".to_string(),
|
name: "➡️".to_string(),
|
||||||
}),
|
}),
|
||||||
url: None,
|
url: None,
|
||||||
disabled: page >= n_pages - 1,
|
disabled: page >= n_pages - 1,
|
||||||
|
sku_id: None,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
})]
|
})]
|
||||||
@@ -153,8 +154,8 @@ pub(crate) async fn queue(
|
|||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
.update_response(&interaction.token)
|
.update_response(&interaction.token)
|
||||||
.embeds(Some(&embeds))?
|
.embeds(Some(&embeds))
|
||||||
.components(Some(&action_row))?
|
.components(Some(&action_row))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ use twilight_model::gateway::payload::incoming::InteractionCreate;
|
|||||||
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
||||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct Handler {
|
pub(crate) struct Handler {
|
||||||
state: State,
|
state: State,
|
||||||
}
|
}
|
||||||
|
|||||||
78
src/main.rs
78
src/main.rs
@@ -12,18 +12,12 @@ mod utils;
|
|||||||
|
|
||||||
use crate::commands::get_chat_commands;
|
use crate::commands::get_chat_commands;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
use futures::StreamExt;
|
|
||||||
use signal::signal_handler;
|
|
||||||
use songbird::{shards::TwilightMap, Songbird};
|
use songbird::{shards::TwilightMap, Songbird};
|
||||||
use state::StateRef;
|
use state::StateRef;
|
||||||
use std::{env, error::Error, str::FromStr, sync::Arc, time::Duration};
|
use std::{env, error::Error, str::FromStr, sync::Arc, time::Duration};
|
||||||
use tokio::select;
|
|
||||||
use tracing::{debug, info};
|
use tracing::{debug, info};
|
||||||
use twilight_cache_inmemory::InMemoryCache;
|
use twilight_cache_inmemory::InMemoryCache;
|
||||||
use twilight_gateway::{
|
use twilight_gateway::{Event, EventTypeFlags, Intents, Shard, StreamExt as _};
|
||||||
stream::{self, ShardEventStream},
|
|
||||||
Intents, Shard,
|
|
||||||
};
|
|
||||||
use twilight_http::Client as HttpClient;
|
use twilight_http::Client as HttpClient;
|
||||||
use twilight_model::id::Id;
|
use twilight_model::id::Id;
|
||||||
use twilight_standby::Standby;
|
use twilight_standby::Standby;
|
||||||
@@ -38,7 +32,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|||||||
|
|
||||||
info!("Starting up...");
|
info!("Starting up...");
|
||||||
|
|
||||||
let (mut shards, state) = {
|
let (shards, state) = {
|
||||||
let db = env::var("DATABASE_URL").map_err(|_| "DATABASE_URL is not set")?;
|
let db = env::var("DATABASE_URL").map_err(|_| "DATABASE_URL is not set")?;
|
||||||
let options = SqliteConnectOptions::from_str(&db)
|
let options = SqliteConnectOptions::from_str(&db)
|
||||||
.expect("could not create options")
|
.expect("could not create options")
|
||||||
@@ -71,7 +65,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|||||||
| Intents::MESSAGE_CONTENT;
|
| Intents::MESSAGE_CONTENT;
|
||||||
let config = twilight_gateway::Config::new(token.clone(), intents);
|
let config = twilight_gateway::Config::new(token.clone(), intents);
|
||||||
let shards: Vec<Shard> =
|
let shards: Vec<Shard> =
|
||||||
stream::create_recommended(&http, config, |_, builder| builder.build())
|
twilight_gateway::create_recommended(&http, config, |_, builder| builder.build())
|
||||||
.await?
|
.await?
|
||||||
.collect();
|
.collect();
|
||||||
let senders = TwilightMap::new(
|
let senders = TwilightMap::new(
|
||||||
@@ -105,36 +99,49 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|||||||
info!("Ready to receive events");
|
info!("Ready to receive events");
|
||||||
|
|
||||||
let handler = Handler::new(Arc::clone(&state));
|
let handler = Handler::new(Arc::clone(&state));
|
||||||
let mut stop_rx = signal_handler();
|
// let mut stop_rx = signal_handler();
|
||||||
let mut stream = ShardEventStream::new(shards.iter_mut());
|
let mut set = tokio::task::JoinSet::new();
|
||||||
loop {
|
|
||||||
select! {
|
for shard in shards {
|
||||||
biased;
|
set.spawn(tokio::spawn(runner(shard, handler.clone(), state.clone())));
|
||||||
_ = 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?;
|
|
||||||
}
|
}
|
||||||
}
|
set.join_next().await;
|
||||||
}
|
|
||||||
// need to grab next event to properly leave voice channels
|
Ok(())
|
||||||
stream.next().await;
|
}
|
||||||
break;
|
|
||||||
},
|
async fn runner(mut shard: Shard, handler: Handler, state: Arc<StateRef>) {
|
||||||
next = stream.next() => {
|
while let Some(item) = shard.next_event(EventTypeFlags::all()).await {
|
||||||
let event = match next {
|
let event = match item {
|
||||||
Some((_, Ok(event))) => event,
|
Ok(event) => event,
|
||||||
Some((_, Err(source))) => {
|
Err(source) => {
|
||||||
tracing::warn!(?source, "error receiving event");
|
tracing::warn!(?source, "error receiving event");
|
||||||
if source.is_fatal() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
None => break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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);
|
debug!("Event: {:?}", &event);
|
||||||
|
|
||||||
state.cache.update(&event);
|
state.cache.update(&event);
|
||||||
@@ -142,8 +149,5 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|||||||
state.songbird.process(&event).await;
|
state.songbird.process(&event).await;
|
||||||
|
|
||||||
handler.act(event).await?;
|
handler.act(event).await?;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use songbird::{input::YoutubeDl, typemap::TypeMapKey};
|
use songbird::input::YoutubeDl;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -6,10 +6,5 @@ pub(crate) struct Metadata {
|
|||||||
pub(crate) title: Option<String>,
|
pub(crate) title: Option<String>,
|
||||||
pub(crate) duration: Option<Duration>,
|
pub(crate) duration: Option<Duration>,
|
||||||
pub(crate) url: String,
|
pub(crate) url: String,
|
||||||
pub(crate) src: YoutubeDl,
|
pub(crate) src: YoutubeDl<'static>,
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct MetadataMap;
|
|
||||||
impl TypeMapKey for MetadataMap {
|
|
||||||
type Value = Metadata;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
use tokio::{
|
// use tokio::{
|
||||||
select,
|
// select,
|
||||||
signal::unix::{signal, SignalKind},
|
// signal::unix::{signal, SignalKind},
|
||||||
sync::watch,
|
// sync::watch,
|
||||||
};
|
// };
|
||||||
|
|
||||||
pub(crate) fn signal_handler() -> watch::Receiver<()> {
|
// pub(crate) fn signal_handler() -> watch::Receiver<()> {
|
||||||
let (stop_tx, stop_rx) = watch::channel(());
|
// let (stop_tx, stop_rx) = watch::channel(());
|
||||||
tokio::spawn(async move {
|
// tokio::spawn(async move {
|
||||||
let mut sigterm = signal(SignalKind::terminate()).unwrap();
|
// let mut sigterm = signal(SignalKind::terminate()).unwrap();
|
||||||
let mut sigint = signal(SignalKind::interrupt()).unwrap();
|
// let mut sigint = signal(SignalKind::interrupt()).unwrap();
|
||||||
loop {
|
// loop {
|
||||||
select! {
|
// select! {
|
||||||
_ = sigterm.recv() => println!("Receive SIGTERM"),
|
// _ = sigterm.recv() => println!("Receive SIGTERM"),
|
||||||
_ = sigint.recv() => println!("Receive SIGTERM"),
|
// _ = sigint.recv() => println!("Receive SIGTERM"),
|
||||||
};
|
// };
|
||||||
stop_tx.send(()).unwrap();
|
// stop_tx.send(()).unwrap();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
stop_rx
|
// stop_rx
|
||||||
}
|
// }
|
||||||
|
|||||||
Reference in New Issue
Block a user