Add response to /random
This commit is contained in:
@@ -78,9 +78,15 @@ pub async fn play_random(
|
||||
join_channel(ctx.serenity_context(), guild.clone(), channel).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();
|
||||
|
||||
println!("{}", ts.subsec_micros());
|
||||
|
||||
// This is far cheaper and easier than using an RNG. No reason to use a full RNG here
|
||||
// anyway.
|
||||
match sounds.get(ts.subsec_micros() as usize % sounds.len()) {
|
||||
@@ -97,6 +103,9 @@ pub async fn play_random(
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
ctx.say(format!("Playing {} (ID {})", sound.name, sound.id))
|
||||
.await?;
|
||||
}
|
||||
|
||||
None => {
|
||||
|
||||
@@ -30,7 +30,6 @@ type Database = MySql;
|
||||
|
||||
pub struct Data {
|
||||
database: Pool<Database>,
|
||||
http: reqwest::Client,
|
||||
guild_data_cache: DashMap<GuildId, Arc<RwLock<GuildData>>>,
|
||||
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();
|
||||
|
||||
Ok(Data {
|
||||
http: reqwest::Client::new(),
|
||||
database,
|
||||
guild_data_cache: Default::default(),
|
||||
join_sound_cache: Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user