Add response to /random

This commit is contained in:
jude 2023-10-22 00:07:04 +01:00
parent bec92177cb
commit 605bc37db6
4 changed files with 11 additions and 4 deletions

2
Cargo.lock generated
View File

@ -2215,7 +2215,7 @@ dependencies = [
[[package]] [[package]]
name = "soundfx-rs" name = "soundfx-rs"
version = "1.5.11" version = "1.5.12"
dependencies = [ dependencies = [
"axum", "axum",
"dashmap", "dashmap",

View File

@ -2,7 +2,7 @@
name = "soundfx-rs" name = "soundfx-rs"
description = "Discord bot for custom sound effects and soundboards" description = "Discord bot for custom sound effects and soundboards"
license = "AGPL-3.0-only" license = "AGPL-3.0-only"
version = "1.5.11" version = "1.5.12"
authors = ["jellywx <judesouthworth@pm.me>"] authors = ["jellywx <judesouthworth@pm.me>"]
edition = "2018" edition = "2018"

View File

@ -78,9 +78,15 @@ pub async fn play_random(
join_channel(ctx.serenity_context(), guild.clone(), channel).await; join_channel(ctx.serenity_context(), guild.clone(), channel).await;
let sounds = ctx.data().guild_sounds(guild.id, None).await?; let sounds = ctx.data().guild_sounds(guild.id, None).await?;
if sounds.len() == 0 {
ctx.say("No sounds in this server!").await?;
return Ok(());
}
let ts = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); let ts = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
println!("{}", ts.subsec_micros());
// This is far cheaper and easier than using an RNG. No reason to use a full RNG here // This is far cheaper and easier than using an RNG. No reason to use a full RNG here
// anyway. // anyway.
match sounds.get(ts.subsec_micros() as usize % sounds.len()) { match sounds.get(ts.subsec_micros() as usize % sounds.len()) {
@ -97,6 +103,9 @@ pub async fn play_random(
) )
.await .await
.unwrap(); .unwrap();
ctx.say(format!("Playing {} (ID {})", sound.name, sound.id))
.await?;
} }
None => { None => {

View File

@ -30,7 +30,6 @@ type Database = MySql;
pub struct Data { pub struct Data {
database: Pool<Database>, database: Pool<Database>,
http: reqwest::Client,
guild_data_cache: DashMap<GuildId, Arc<RwLock<GuildData>>>, guild_data_cache: DashMap<GuildId, Arc<RwLock<GuildData>>>,
join_sound_cache: DashMap<UserId, DashMap<Option<GuildId>, Option<u32>>>, join_sound_cache: DashMap<UserId, DashMap<Option<GuildId>, Option<u32>>>,
} }
@ -159,7 +158,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.unwrap(); .unwrap();
Ok(Data { Ok(Data {
http: reqwest::Client::new(),
database, database,
guild_data_cache: Default::default(), guild_data_cache: Default::default(),
join_sound_cache: Default::default(), join_sound_cache: Default::default(),