Compare commits
1 Commits
message_fo
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
6b3629436a
|
@@ -5,9 +5,6 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
paths-ignore:
|
|
||||||
- 'README.md'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-image:
|
release-image:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -29,5 +26,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
platforms: |
|
platforms: |
|
||||||
linux/amd64
|
linux/amd64
|
||||||
|
# linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: jheuel/ohrwurm:latest
|
tags: jheuel/ohrwurm:latest
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ twilight-util = { version = "0.15", 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"
|
||||||
url = "2.5.1"
|
url = "2.5.0"
|
||||||
anyhow = "1.0.86"
|
anyhow = "1.0.86"
|
||||||
dashmap = "5.5.3"
|
dashmap = "5.5.3"
|
||||||
async-trait = "0.1.80"
|
async-trait = "0.1.80"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
Ohrwurm is a user-friendly bot designed to play music in Discord voice chats. Once added to your server, you can request a song using the command `/play {query}`, where query can be a URL to a YouTube video or playlist, or a simple search term. The bot will fetch the song and start playing it. You can pause the music with `/pause`, resume playback with `/resume`, and stop and clear the queue with `/stop`. If the bot is alone in a voice chat, it will automatically leave, but you can also manually make it leave with the `/leave` command.
|
Ohrwurm is a user-friendly bot designed to play music in Discord voice chats. Once added to your server, you can request a song using the command `/play {query}`, where query can be a URL to a YouTube video or playlist, or a simple search term. The bot will fetch the song and start playing it. You can pause the music with `/pause`, resume playback with `/resume`, and stop and clear the queue with `/stop`. If the bot is alone in a voice chat, it will automatically leave, but you can also manually make it leave with the `/leave` command.
|
||||||
|
|
||||||
# Deployment
|
# Deployment
|
||||||
To deploy Ohrwurm with Docker, you can use the [provided Docker image](https://hub.docker.com/r/jheuel/ohrwurm):
|
To deploy Ohrwurm with Docker, you can use the [provided Docker](https://hub.docker.com/r/jheuel/ohrwurm) image:
|
||||||
```bash
|
```bash
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name ohrwurm \
|
--name ohrwurm \
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ pub(crate) async fn join_channel(
|
|||||||
call.deafen(true).await?;
|
call.deafen(true).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create guild config
|
|
||||||
state.guild_settings.entry(guild_id).or_default();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,6 @@
|
|||||||
use crate::state::{State, StateRef};
|
use crate::state::State;
|
||||||
use std::{error::Error, sync::Arc};
|
use std::error::Error;
|
||||||
use twilight_model::{
|
use twilight_model::gateway::payload::incoming::InteractionCreate;
|
||||||
gateway::payload::incoming::InteractionCreate,
|
|
||||||
id::{marker::GuildMarker, Id},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) async fn leave_channel(
|
|
||||||
guild_id: Id<GuildMarker>,
|
|
||||||
state: Arc<StateRef>,
|
|
||||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
|
||||||
// stop playing
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
|
||||||
let call = call_lock.lock().await;
|
|
||||||
call.queue().stop();
|
|
||||||
}
|
|
||||||
// leave the voice channel
|
|
||||||
state.songbird.leave(guild_id).await?;
|
|
||||||
|
|
||||||
// reset guild settings
|
|
||||||
state.guild_settings.remove(&guild_id);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) async fn leave(
|
pub(crate) async fn leave(
|
||||||
interaction: Box<InteractionCreate>,
|
interaction: Box<InteractionCreate>,
|
||||||
@@ -36,8 +16,6 @@ pub(crate) async fn leave(
|
|||||||
let Some(guild_id) = interaction.guild_id else {
|
let Some(guild_id) = interaction.guild_id else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
state.songbird.leave(guild_id).await?;
|
||||||
leave_channel(guild_id, Arc::clone(&state)).await?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::metadata::MetadataMap;
|
use crate::metadata::MetadataMap;
|
||||||
use crate::state::{State, StateRef};
|
use crate::state::{Settings, State, StateRef};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use songbird::{Event, EventContext, EventHandler, TrackEvent};
|
use songbird::{Event, EventContext, EventHandler, TrackEvent};
|
||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
@@ -29,8 +29,14 @@ pub(crate) async fn loop_queue(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
state
|
||||||
|
.guild_settings
|
||||||
|
.entry(guild_id)
|
||||||
|
.or_insert_with(|| Settings { loop_queue: false });
|
||||||
|
|
||||||
state.guild_settings.entry(guild_id).and_modify(|settings| {
|
state.guild_settings.entry(guild_id).and_modify(|settings| {
|
||||||
settings.loop_queue = !settings.loop_queue;
|
settings.loop_queue = !settings.loop_queue;
|
||||||
|
println!("loop_queue: {}", settings.loop_queue);
|
||||||
});
|
});
|
||||||
|
|
||||||
let looping = state
|
let looping = state
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ pub(crate) use join::join;
|
|||||||
|
|
||||||
mod leave;
|
mod leave;
|
||||||
pub(crate) use leave::leave;
|
pub(crate) use leave::leave;
|
||||||
pub(crate) use leave::leave_channel;
|
|
||||||
|
|
||||||
mod pause;
|
mod pause;
|
||||||
pub(crate) use pause::pause;
|
pub(crate) use pause::pause;
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ use std::ops::Sub;
|
|||||||
use std::{error::Error, time::Duration};
|
use std::{error::Error, time::Duration};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use twilight_model::channel::message::embed::{
|
|
||||||
EmbedAuthor, EmbedField, EmbedFooter, EmbedThumbnail,
|
|
||||||
};
|
|
||||||
use twilight_model::channel::message::MessageFlags;
|
use twilight_model::channel::message::MessageFlags;
|
||||||
use twilight_model::gateway::payload::incoming::InteractionCreate;
|
use twilight_model::gateway::payload::incoming::InteractionCreate;
|
||||||
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
use twilight_model::http::interaction::{InteractionResponse, InteractionResponseType};
|
||||||
@@ -59,7 +56,6 @@ async fn get_tracks(
|
|||||||
if stderr.contains("YouTube said: The playlist does not exist.") {
|
if stderr.contains("YouTube said: The playlist does not exist.") {
|
||||||
return Err("YouTube said: The playlist does not exist.".into());
|
return Err("YouTube said: The playlist does not exist.".into());
|
||||||
}
|
}
|
||||||
return Err(stderr.into());
|
|
||||||
}
|
}
|
||||||
return Err("No tracks found".into());
|
return Err("No tracks found".into());
|
||||||
}
|
}
|
||||||
@@ -165,35 +161,17 @@ pub(crate) async fn play(
|
|||||||
call.queue().resume()?;
|
call.queue().resume()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TrackType {
|
|
||||||
url: String,
|
|
||||||
title: Option<String>,
|
|
||||||
duration_string: String,
|
|
||||||
channel: String,
|
|
||||||
thumbnail: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut tracks_added = vec![];
|
let mut tracks_added = vec![];
|
||||||
for yttrack in &tracks {
|
for track in &tracks {
|
||||||
tracing::debug!("track: {:?}", yttrack);
|
tracing::debug!("track: {:?}", track);
|
||||||
let url = yttrack
|
let url = track.url.clone().or(track.original_url.clone()).ok_or("")?;
|
||||||
.url
|
|
||||||
.clone()
|
|
||||||
.or(yttrack.original_url.clone())
|
|
||||||
.ok_or("")?;
|
|
||||||
let mut src = YoutubeDl::new(reqwest::Client::new(), url.clone());
|
let mut src = YoutubeDl::new(reqwest::Client::new(), url.clone());
|
||||||
let src_copy = src.clone();
|
let src_copy = src.clone();
|
||||||
let track: Track = src_copy.into();
|
let track: Track = src_copy.into();
|
||||||
|
|
||||||
if let Ok(metadata) = src.aux_metadata().await {
|
if let Ok(metadata) = src.aux_metadata().await {
|
||||||
debug!("metadata: {:?}", metadata);
|
debug!("metadata: {:?}", metadata);
|
||||||
tracks_added.push(TrackType {
|
tracks_added.push((url.clone(), metadata.title.clone()));
|
||||||
url: url.clone(),
|
|
||||||
title: metadata.title.clone(),
|
|
||||||
duration_string: yttrack.duration_string.clone(),
|
|
||||||
channel: yttrack.channel.clone(),
|
|
||||||
thumbnail: metadata.thumbnail.clone(),
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||||
let mut call = call_lock.lock().await;
|
let mut call = call_lock.lock().await;
|
||||||
@@ -219,58 +197,16 @@ pub(crate) async fn play(
|
|||||||
}
|
}
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
let num_tracks_added = tracks_added.len();
|
let num_tracks_added = tracks_added.len();
|
||||||
let embeds = match num_tracks_added {
|
match num_tracks_added {
|
||||||
0 => {
|
0 => {}
|
||||||
vec![]
|
|
||||||
}
|
|
||||||
1 => {
|
1 => {
|
||||||
let track = tracks_added.first().unwrap();
|
let (title, url) = if let Some(track) = tracks_added.first() {
|
||||||
|
let track = track.clone();
|
||||||
let host = Url::parse(&track.url)?;
|
(track.1.unwrap_or("Unknown".to_string()), track.0)
|
||||||
let host = host
|
} else {
|
||||||
.host_str()
|
("Unknown".to_string(), "".to_string())
|
||||||
.unwrap_or_default()
|
};
|
||||||
.trim_start_matches("www.");
|
content = format!("Added [{}]({}) to the queue", title, url);
|
||||||
let mut embed = EmbedBuilder::new()
|
|
||||||
.author(EmbedAuthor {
|
|
||||||
name: "🔊 Added to queue".to_string(),
|
|
||||||
icon_url: None,
|
|
||||||
proxy_icon_url: None,
|
|
||||||
url: None,
|
|
||||||
})
|
|
||||||
.title(track.title.clone().unwrap_or("Unknown".to_string()))
|
|
||||||
.url(track.url.clone())
|
|
||||||
.color(colors::BLURPLE)
|
|
||||||
.footer(EmbedFooter {
|
|
||||||
text: format!("Streaming from {}", host),
|
|
||||||
icon_url: Some(format!(
|
|
||||||
"https://www.google.com/s2/favicons?domain={}",
|
|
||||||
host
|
|
||||||
)),
|
|
||||||
proxy_icon_url: None,
|
|
||||||
})
|
|
||||||
.field(EmbedField {
|
|
||||||
inline: true,
|
|
||||||
name: "Duration".to_string(),
|
|
||||||
value: track.duration_string.clone(),
|
|
||||||
})
|
|
||||||
.field(EmbedField {
|
|
||||||
inline: true,
|
|
||||||
name: "Channel".to_string(),
|
|
||||||
value: track.channel.clone(),
|
|
||||||
})
|
|
||||||
.build();
|
|
||||||
|
|
||||||
if let Some(thumbnail) = &track.thumbnail {
|
|
||||||
embed.thumbnail = Some(EmbedThumbnail {
|
|
||||||
height: None,
|
|
||||||
proxy_url: None,
|
|
||||||
url: thumbnail.to_string(),
|
|
||||||
width: None,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
vec![embed]
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let first_track = tracks.first().unwrap();
|
let first_track = tracks.first().unwrap();
|
||||||
@@ -291,14 +227,13 @@ pub(crate) async fn play(
|
|||||||
"Added {} tracks to the queue:\n",
|
"Added {} tracks to the queue:\n",
|
||||||
num_tracks_added
|
num_tracks_added
|
||||||
));
|
));
|
||||||
let embed = EmbedBuilder::new()
|
|
||||||
.description(content)
|
|
||||||
.color(colors::BLURPLE)
|
|
||||||
.build();
|
|
||||||
vec![embed]
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
let embeds = vec![EmbedBuilder::new()
|
||||||
|
.description(content)
|
||||||
|
.color(colors::BLURPLE)
|
||||||
|
.build()];
|
||||||
state
|
state
|
||||||
.http
|
.http
|
||||||
.interaction(interaction.application_id)
|
.interaction(interaction.application_id)
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ pub(crate) async fn stop(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
state.guild_settings.entry(guild_id).and_modify(|settings| {
|
|
||||||
settings.loop_queue = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||||
let call = call_lock.lock().await;
|
let call = call_lock.lock().await;
|
||||||
call.queue().stop();
|
call.queue().stop();
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
use crate::commands::queue::{build_action_row, build_queue_embeds, TRACKS_PER_PAGE};
|
use crate::commands::queue::{build_action_row, build_queue_embeds, TRACKS_PER_PAGE};
|
||||||
use crate::commands::{
|
use crate::commands::{delete, join, leave, loop_queue, pause, play, queue, resume, skip, stop};
|
||||||
delete, join, leave, leave_channel, loop_queue, pause, play, queue, resume, skip, stop,
|
|
||||||
};
|
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@@ -65,7 +63,13 @@ pub(crate) async fn leave_if_alone(
|
|||||||
|
|
||||||
// count is 1 if the bot is the only one in the channel
|
// count is 1 if the bot is the only one in the channel
|
||||||
if count == 1 {
|
if count == 1 {
|
||||||
leave_channel(guild_id, Arc::clone(&state)).await?;
|
// stop playing
|
||||||
|
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||||
|
let call = call_lock.lock().await;
|
||||||
|
call.queue().stop();
|
||||||
|
}
|
||||||
|
// leave the voice channel
|
||||||
|
state.songbird.leave(guild_id).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/state.rs
12
src/state.rs
@@ -13,18 +13,6 @@ pub(crate) struct Settings {
|
|||||||
pub(crate) loop_queue: bool,
|
pub(crate) loop_queue: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
|
||||||
pub(crate) fn new() -> Self {
|
|
||||||
Self { loop_queue: false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for Settings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct StateRef {
|
pub(crate) struct StateRef {
|
||||||
pub(crate) http: HttpClient,
|
pub(crate) http: HttpClient,
|
||||||
|
|||||||
Reference in New Issue
Block a user