aboutsummaryrefslogtreecommitdiffstats
path: root/src/bot
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot')
-rw-r--r--src/bot/master.rs18
-rw-r--r--src/bot/music.rs16
2 files changed, 29 insertions, 5 deletions
diff --git a/src/bot/master.rs b/src/bot/master.rs
index 67867ef..9b33744 100644
--- a/src/bot/master.rs
+++ b/src/bot/master.rs
@@ -222,6 +222,7 @@ impl MasterBot {
name: name,
state: bot.state(),
volume: bot.volume(),
+ position: bot.position(),
currently_playing: bot.currently_playing(),
playlist: bot.playlist_to_vec(),
})
@@ -237,6 +238,7 @@ impl MasterBot {
name: name.clone(),
state: bot.state(),
volume: bot.volume(),
+ position: bot.position(),
currently_playing: bot.currently_playing(),
playlist: bot.playlist_to_vec(),
};
@@ -247,6 +249,18 @@ impl MasterBot {
result
}
+ pub fn bot_names(&self) -> Vec<String> {
+ let music_bots = self.music_bots.read().unwrap();
+
+ let len = music_bots.connected_bots.len();
+ let mut result = Vec::with_capacity(len);
+ for (name, _) in &music_bots.connected_bots {
+ result.push(name.clone());
+ }
+
+ result
+ }
+
pub fn quit(&self, reason: String) {
let music_bots = self.music_bots.read().unwrap();
for (_, bot) in &music_bots.connected_bots {
@@ -267,6 +281,8 @@ pub struct MasterArgs {
pub channel: Option<String>,
#[serde(default = "default_verbose")]
pub verbose: u8,
+ pub domain: String,
+ pub bind_address: String,
pub names: Vec<String>,
pub id: Identity,
pub ids: Vec<Identity>,
@@ -301,6 +317,8 @@ impl MasterArgs {
ids: self.ids,
local,
address,
+ domain: self.domain,
+ bind_address: self.bind_address,
id: self.id,
channel,
verbose,
diff --git a/src/bot/music.rs b/src/bot/music.rs
index 0def280..41976e5 100644
--- a/src/bot/music.rs
+++ b/src/bot/music.rs
@@ -2,6 +2,7 @@ use std::future::Future;
use std::io::BufRead;
use std::sync::{Arc, RwLock};
use std::thread;
+use std::time::Duration;
use humantime;
use log::{debug, info};
@@ -193,9 +194,10 @@ impl MusicBot {
self.player.play().unwrap();
}
- pub async fn add_audio(&self, url: String) {
+ pub async fn add_audio(&self, url: String, user: String) {
match crate::youtube_dl::get_audio_download_url(url).await {
- Ok(metadata) => {
+ Ok(mut metadata) => {
+ metadata.added_by = user;
info!("Found audio url: {}", metadata.url);
let mut playlist = self.playlist.write().expect("RwLock was not poisoned");
@@ -232,6 +234,10 @@ impl MusicBot {
self.player.volume()
}
+ pub fn position(&self) -> Option<Duration> {
+ self.player.position()
+ }
+
pub fn currently_playing(&self) -> Option<AudioMetadata> {
self.player.currently_playing()
}
@@ -278,7 +284,7 @@ impl MusicBot {
let tokens = msg[1..].split_whitespace().collect::<Vec<_>>();
match Command::from_iter_safe(&tokens) {
- Ok(args) => self.on_command(args).await?,
+ Ok(args) => self.on_command(args, message.invoker).await?,
Err(e) if e.kind == structopt::clap::ErrorKind::HelpDisplayed => {
self.send_message(&format!("\n{}", e.message));
}
@@ -289,7 +295,7 @@ impl MusicBot {
Ok(())
}
- async fn on_command(&self, command: Command) -> Result<(), AudioPlayerError> {
+ async fn on_command(&self, command: Command, invoker: Invoker) -> Result<(), AudioPlayerError> {
match command {
Command::Play => {
let playlist = self.playlist.read().expect("RwLock was not poisoned");
@@ -306,7 +312,7 @@ impl MusicBot {
// strip bbcode tags from url
let url = url.replace("[URL]", "").replace("[/URL]", "");
- self.add_audio(url.to_string()).await;
+ self.add_audio(url.to_string(), invoker.name).await;
}
Command::Pause => {
self.player.pause()?;