removed popular command. fix for ambience command
This commit is contained in:
parent
6f86f2afa0
commit
1cc1068788
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1706,7 +1706,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "soundfx-rs"
|
name = "soundfx-rs"
|
||||||
version = "1.4.2"
|
version = "1.4.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dashmap",
|
"dashmap",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "soundfx-rs"
|
name = "soundfx-rs"
|
||||||
version = "1.4.2"
|
version = "1.4.3"
|
||||||
authors = ["jellywx <judesouthworth@pm.me>"]
|
authors = ["jellywx <judesouthworth@pm.me>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ pub async fn upload_new_sound(
|
|||||||
invoke.respond(
|
invoke.respond(
|
||||||
ctx.http.clone(),
|
ctx.http.clone(),
|
||||||
CreateGenericResponse::new().content(format!(
|
CreateGenericResponse::new().content(format!(
|
||||||
"You have reached the maximum number of sounds ({}). Either delete some with `?delete` or join our Patreon for unlimited uploads at **https://patreon.com/jellywx**",
|
"You have reached the maximum number of sounds ({}). Either delete some with `/delete` or join our Patreon for unlimited uploads at **https://patreon.com/jellywx**",
|
||||||
*MAX_SOUNDS,
|
*MAX_SOUNDS,
|
||||||
))).await?;
|
))).await?;
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ pub async fn upload_new_sound(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Usage: `?upload <name>`. Please ensure the name provided is less than 20 characters in length")).await?;
|
invoke.respond(ctx.http.clone(), CreateGenericResponse::new().content("Usage: `/upload <name>`. Please ensure the name provided is less than 20 characters in length")).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -108,60 +108,78 @@ pub async fn play_ambience(
|
|||||||
|
|
||||||
match channel_to_join {
|
match channel_to_join {
|
||||||
Some(user_channel) => {
|
Some(user_channel) => {
|
||||||
let search_name = args.named("name").unwrap().to_lowercase();
|
|
||||||
let audio_index = ctx.data.read().await.get::<AudioIndex>().cloned().unwrap();
|
let audio_index = ctx.data.read().await.get::<AudioIndex>().cloned().unwrap();
|
||||||
|
|
||||||
if let Some(filename) = audio_index.get(&search_name) {
|
if let Some(search_name) = args.named("name") {
|
||||||
let (track, track_handler) = create_player(
|
if let Some(filename) = audio_index.get(search_name) {
|
||||||
Input::try_from(
|
let (track, track_handler) = create_player(
|
||||||
Memory::new(ffmpeg(format!("audio/{}", filename)).await.unwrap()).unwrap(),
|
Input::try_from(
|
||||||
)
|
Memory::new(ffmpeg(format!("audio/{}", filename)).await.unwrap())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
let (call_handler, _) = join_channel(ctx, guild.clone(), user_channel).await;
|
let (call_handler, _) = join_channel(ctx, guild.clone(), user_channel).await;
|
||||||
let guild_data = ctx.guild_data(guild).await.unwrap();
|
let guild_data = ctx.guild_data(guild).await.unwrap();
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut lock = call_handler.lock().await;
|
let mut lock = call_handler.lock().await;
|
||||||
|
|
||||||
lock.play(track);
|
lock.play(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = track_handler.set_volume(guild_data.read().await.volume as f32 / 100.0);
|
||||||
|
let _ = track_handler.add_event(
|
||||||
|
Event::Periodic(
|
||||||
|
track_handler.metadata().duration.unwrap() - Duration::from_millis(200),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
RestartTrack {},
|
||||||
|
);
|
||||||
|
|
||||||
|
invoke
|
||||||
|
.respond(
|
||||||
|
ctx.http.clone(),
|
||||||
|
CreateGenericResponse::new()
|
||||||
|
.content(format!("Playing ambience **{}**", search_name)),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
|
invoke
|
||||||
|
.respond(
|
||||||
|
ctx.http.clone(),
|
||||||
|
CreateGenericResponse::new().embed(|e| {
|
||||||
|
e.title("Not Found").description(format!(
|
||||||
|
"Could not find ambience sound by name **{}**
|
||||||
|
|
||||||
|
__Available ambience sounds:__
|
||||||
|
{}",
|
||||||
|
search_name,
|
||||||
|
audio_index
|
||||||
|
.keys()
|
||||||
|
.into_iter()
|
||||||
|
.map(|i| i.as_str())
|
||||||
|
.collect::<Vec<&str>>()
|
||||||
|
.join("\n")
|
||||||
|
))
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = track_handler.set_volume(guild_data.read().await.volume as f32 / 100.0);
|
|
||||||
let _ = track_handler.add_event(
|
|
||||||
Event::Periodic(
|
|
||||||
track_handler.metadata().duration.unwrap() - Duration::from_millis(200),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
RestartTrack {},
|
|
||||||
);
|
|
||||||
|
|
||||||
invoke
|
|
||||||
.respond(
|
|
||||||
ctx.http.clone(),
|
|
||||||
CreateGenericResponse::new()
|
|
||||||
.content(format!("Playing ambience **{}**", search_name)),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
} else {
|
||||||
invoke
|
invoke
|
||||||
.respond(
|
.respond(
|
||||||
ctx.http.clone(),
|
ctx.http.clone(),
|
||||||
CreateGenericResponse::new().embed(|e| {
|
CreateGenericResponse::new().embed(|e| {
|
||||||
e.title("Not Found").description(format!(
|
e.title("Available Sounds").description(
|
||||||
"Could not find ambience sound by name **{}**
|
|
||||||
|
|
||||||
__Available ambience sounds:__
|
|
||||||
{}",
|
|
||||||
search_name,
|
|
||||||
audio_index
|
audio_index
|
||||||
.keys()
|
.keys()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|i| i.as_str())
|
.map(|i| i.as_str())
|
||||||
.collect::<Vec<&str>>()
|
.collect::<Vec<&str>>()
|
||||||
.join("\n")
|
.join("\n"),
|
||||||
))
|
)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -14,13 +14,7 @@ fn format_search_results(search_results: Vec<Sound>) -> CreateGenericResponse {
|
|||||||
let field_iter = search_results
|
let field_iter = search_results
|
||||||
.iter()
|
.iter()
|
||||||
.take(25)
|
.take(25)
|
||||||
.map(|item| {
|
.map(|item| (&item.name, format!("ID: {}", item.id), true))
|
||||||
(
|
|
||||||
&item.name,
|
|
||||||
format!("ID: {}\nPlays: {}", item.id, item.plays),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.filter(|item| {
|
.filter(|item| {
|
||||||
current_character_count += item.0.len() + item.1.len();
|
current_character_count += item.0.len() + item.1.len();
|
||||||
|
|
||||||
@ -58,11 +52,11 @@ pub async fn list_sounds(
|
|||||||
let mut message_buffer;
|
let mut message_buffer;
|
||||||
|
|
||||||
if args.named("me").map(|i| i.to_owned()) == Some("me".to_string()) {
|
if args.named("me").map(|i| i.to_owned()) == Some("me".to_string()) {
|
||||||
sounds = Sound::get_user_sounds(invoke.author_id(), pool).await?;
|
sounds = Sound::user_sounds(invoke.author_id(), pool).await?;
|
||||||
|
|
||||||
message_buffer = "All your sounds: ".to_string();
|
message_buffer = "All your sounds: ".to_string();
|
||||||
} else {
|
} else {
|
||||||
sounds = Sound::get_guild_sounds(invoke.guild_id().unwrap(), pool).await?;
|
sounds = Sound::guild_sounds(invoke.guild_id().unwrap(), pool).await?;
|
||||||
|
|
||||||
message_buffer = "All sounds on this server: ".to_string();
|
message_buffer = "All sounds on this server: ".to_string();
|
||||||
}
|
}
|
||||||
@ -141,42 +135,6 @@ pub async fn search_sounds(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command("popular")]
|
|
||||||
#[group("Search")]
|
|
||||||
#[description("Show popular sounds")]
|
|
||||||
pub async fn show_popular_sounds(
|
|
||||||
ctx: &Context,
|
|
||||||
invoke: &(dyn CommandInvoke + Sync + Send),
|
|
||||||
_args: Args,
|
|
||||||
) -> CommandResult {
|
|
||||||
let pool = ctx
|
|
||||||
.data
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.get::<MySQL>()
|
|
||||||
.cloned()
|
|
||||||
.expect("Could not get SQLPool from data");
|
|
||||||
|
|
||||||
let search_results = sqlx::query_as_unchecked!(
|
|
||||||
Sound,
|
|
||||||
"
|
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
|
||||||
FROM sounds
|
|
||||||
WHERE public = 1
|
|
||||||
ORDER BY plays DESC
|
|
||||||
LIMIT 25
|
|
||||||
"
|
|
||||||
)
|
|
||||||
.fetch_all(&pool)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
invoke
|
|
||||||
.respond(ctx.http.clone(), format_search_results(search_results))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[command("random")]
|
#[command("random")]
|
||||||
#[group("Search")]
|
#[group("Search")]
|
||||||
#[description("Show a page of random sounds")]
|
#[description("Show a page of random sounds")]
|
||||||
@ -196,7 +154,7 @@ pub async fn show_random_sounds(
|
|||||||
let search_results = sqlx::query_as_unchecked!(
|
let search_results = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE public = 1
|
WHERE public = 1
|
||||||
ORDER BY rand()
|
ORDER BY rand()
|
||||||
|
@ -137,7 +137,7 @@ impl EventHandler for Handler {
|
|||||||
let mut sound = sqlx::query_as_unchecked!(
|
let mut sound = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
",
|
",
|
||||||
|
@ -44,7 +44,7 @@ impl CtxGuildData for Context {
|
|||||||
} else {
|
} else {
|
||||||
let pool = self.data.read().await.get::<MySQL>().cloned().unwrap();
|
let pool = self.data.read().await.get::<MySQL>().cloned().unwrap();
|
||||||
|
|
||||||
match GuildData::get_from_id(guild_id, pool).await {
|
match GuildData::from_id(guild_id, pool).await {
|
||||||
Ok(d) => {
|
Ok(d) => {
|
||||||
let lock = Arc::new(RwLock::new(d));
|
let lock = Arc::new(RwLock::new(d));
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ impl CtxGuildData for Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GuildData {
|
impl GuildData {
|
||||||
pub async fn get_from_id<G: Into<GuildId>>(
|
pub async fn from_id<G: Into<GuildId>>(
|
||||||
guild_id: G,
|
guild_id: G,
|
||||||
db_pool: MySqlPool,
|
db_pool: MySqlPool,
|
||||||
) -> Result<GuildData, sqlx::Error> {
|
) -> Result<GuildData, sqlx::Error> {
|
||||||
|
29
src/main.rs
29
src/main.rs
@ -8,7 +8,7 @@ mod framework;
|
|||||||
mod guild_data;
|
mod guild_data;
|
||||||
mod sound;
|
mod sound;
|
||||||
|
|
||||||
use std::{collections::HashMap, env, sync::Arc, time::Duration};
|
use std::{collections::HashMap, env, sync::Arc};
|
||||||
|
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
@ -92,9 +92,6 @@ async fn play_audio(
|
|||||||
|
|
||||||
call_handler.play(track);
|
call_handler.play(track);
|
||||||
|
|
||||||
sound.plays += 1;
|
|
||||||
sound.commit(mysql_pool).await?;
|
|
||||||
|
|
||||||
Ok(track_handler)
|
Ok(track_handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +259,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||||||
// search commands
|
// search commands
|
||||||
.add_command(&cmds::search::LIST_SOUNDS_COMMAND)
|
.add_command(&cmds::search::LIST_SOUNDS_COMMAND)
|
||||||
.add_command(&cmds::search::SEARCH_SOUNDS_COMMAND)
|
.add_command(&cmds::search::SEARCH_SOUNDS_COMMAND)
|
||||||
.add_command(&cmds::search::SHOW_POPULAR_SOUNDS_COMMAND)
|
|
||||||
.add_command(&cmds::search::SHOW_RANDOM_SOUNDS_COMMAND);
|
.add_command(&cmds::search::SHOW_RANDOM_SOUNDS_COMMAND);
|
||||||
|
|
||||||
if audio_index.is_some() {
|
if audio_index.is_some() {
|
||||||
@ -310,29 +306,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|||||||
|
|
||||||
framework_arc.build_slash(&client.cache_and_http.http).await;
|
framework_arc.build_slash(&client.cache_and_http.http).await;
|
||||||
|
|
||||||
let shard_manager = client.shard_manager.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
loop {
|
|
||||||
{
|
|
||||||
let mut shards = shard_manager
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.runners
|
|
||||||
.lock()
|
|
||||||
.await
|
|
||||||
.iter()
|
|
||||||
.map(|(id, shard)| format!("\t{} {}", id.0, shard.stage))
|
|
||||||
.collect::<Vec<String>>();
|
|
||||||
|
|
||||||
shards.sort();
|
|
||||||
|
|
||||||
info!("Shard Status: [\n{}\n]", shards.join("\n"));
|
|
||||||
}
|
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if let Ok((Some(lower), Some(upper))) = env::var("SHARD_RANGE").map(|sr| {
|
if let Ok((Some(lower), Some(upper))) = env::var("SHARD_RANGE").map(|sr| {
|
||||||
let mut split = sr
|
let mut split = sr
|
||||||
.split(',')
|
.split(',')
|
||||||
|
17
src/sound.rs
17
src/sound.rs
@ -110,7 +110,6 @@ WHERE
|
|||||||
pub struct Sound {
|
pub struct Sound {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub id: u32,
|
pub id: u32,
|
||||||
pub plays: u32,
|
|
||||||
pub public: bool,
|
pub public: bool,
|
||||||
pub server_id: u64,
|
pub server_id: u64,
|
||||||
pub uploader_id: Option<u64>,
|
pub uploader_id: Option<u64>,
|
||||||
@ -151,7 +150,7 @@ impl Sound {
|
|||||||
let sound = sqlx::query_as_unchecked!(
|
let sound = sqlx::query_as_unchecked!(
|
||||||
Self,
|
Self,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE id = ? AND (
|
WHERE id = ? AND (
|
||||||
public = 1 OR
|
public = 1 OR
|
||||||
@ -175,7 +174,7 @@ SELECT name, id, plays, public, server_id, uploader_id
|
|||||||
sound = sqlx::query_as_unchecked!(
|
sound = sqlx::query_as_unchecked!(
|
||||||
Self,
|
Self,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE name = ? AND (
|
WHERE name = ? AND (
|
||||||
public = 1 OR
|
public = 1 OR
|
||||||
@ -196,7 +195,7 @@ SELECT name, id, plays, public, server_id, uploader_id
|
|||||||
sound = sqlx::query_as_unchecked!(
|
sound = sqlx::query_as_unchecked!(
|
||||||
Self,
|
Self,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE name LIKE CONCAT('%', ?, '%') AND (
|
WHERE name LIKE CONCAT('%', ?, '%') AND (
|
||||||
public = 1 OR
|
public = 1 OR
|
||||||
@ -311,12 +310,10 @@ SELECT COUNT(1) as count
|
|||||||
"
|
"
|
||||||
UPDATE sounds
|
UPDATE sounds
|
||||||
SET
|
SET
|
||||||
plays = ?,
|
|
||||||
public = ?
|
public = ?
|
||||||
WHERE
|
WHERE
|
||||||
id = ?
|
id = ?
|
||||||
",
|
",
|
||||||
self.plays,
|
|
||||||
self.public,
|
self.public,
|
||||||
self.id
|
self.id
|
||||||
)
|
)
|
||||||
@ -408,14 +405,14 @@ INSERT INTO sounds (name, server_id, uploader_id, public, src)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_user_sounds<U: Into<u64>>(
|
pub async fn user_sounds<U: Into<u64>>(
|
||||||
user_id: U,
|
user_id: U,
|
||||||
db_pool: MySqlPool,
|
db_pool: MySqlPool,
|
||||||
) -> Result<Vec<Sound>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Vec<Sound>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let sounds = sqlx::query_as_unchecked!(
|
let sounds = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE uploader_id = ?
|
WHERE uploader_id = ?
|
||||||
",
|
",
|
||||||
@ -427,14 +424,14 @@ SELECT name, id, plays, public, server_id, uploader_id
|
|||||||
Ok(sounds)
|
Ok(sounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_guild_sounds<G: Into<u64>>(
|
pub async fn guild_sounds<G: Into<u64>>(
|
||||||
guild_id: G,
|
guild_id: G,
|
||||||
db_pool: MySqlPool,
|
db_pool: MySqlPool,
|
||||||
) -> Result<Vec<Sound>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Vec<Sound>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let sounds = sqlx::query_as_unchecked!(
|
let sounds = sqlx::query_as_unchecked!(
|
||||||
Sound,
|
Sound,
|
||||||
"
|
"
|
||||||
SELECT name, id, plays, public, server_id, uploader_id
|
SELECT name, id, public, server_id, uploader_id
|
||||||
FROM sounds
|
FROM sounds
|
||||||
WHERE server_id = ?
|
WHERE server_id = ?
|
||||||
",
|
",
|
||||||
|
Loading…
Reference in New Issue
Block a user