Compare commits

..

No commits in common. "48b50f783d0847732cd62565a7471b11a76b85a7" and "bec92177cb611c37fc8da9a2a8747b0978467244" have entirely different histories.

6 changed files with 8 additions and 27 deletions

2
Cargo.lock generated
View File

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

View File

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

View File

@ -1,8 +1,6 @@
use poise::serenity_prelude::{Attachment, GuildId, RoleId};
use tokio::fs::File;
#[cfg(feature = "metrics")]
use crate::metrics::{DELETE_COUNTER, UPLOAD_COUNTER};
use crate::{
cmds::autocomplete_sound,
consts::{MAX_SOUNDS, PATREON_GUILD, PATREON_ROLE},
@ -23,9 +21,6 @@ pub async fn upload_new_sound(
#[description = "Name to upload sound to"] name: String,
#[description = "Sound file (max. 2MB)"] file: Attachment,
) -> Result<(), Error> {
#[cfg(feature = "metrics")]
UPLOAD_COUNTER.inc();
ctx.defer().await?;
fn is_numeric(s: &String) -> bool {
@ -115,9 +110,6 @@ pub async fn delete_sound(
#[autocomplete = "autocomplete_sound"]
name: String,
) -> Result<(), Error> {
#[cfg(feature = "metrics")]
DELETE_COUNTER.inc();
let pool = ctx.data().database.clone();
let uid = ctx.author().id.0;

View File

@ -25,13 +25,13 @@ pub async fn play(
#[channel_types("Voice")]
channel: Option<GuildChannel>,
) -> Result<(), Error> {
#[cfg(feature = "metrics")]
PLAY_COUNTER.inc();
ctx.defer().await?;
let guild = ctx.guild().unwrap();
#[cfg(feature = "metrics")]
PLAY_COUNTER.inc();
ctx.say(
play_from_query(
&ctx.serenity_context(),
@ -78,15 +78,9 @@ 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()) {
@ -103,9 +97,6 @@ pub async fn play_random(
)
.await
.unwrap();
ctx.say(format!("Playing {} (ID {})", sound.name, sound.id))
.await?;
}
None => {

View File

@ -30,6 +30,7 @@ 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>>>,
}
@ -158,6 +159,7 @@ 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(),

View File

@ -8,11 +8,7 @@ use prometheus::{register_int_counter, IntCounter, Registry};
lazy_static! {
static ref REGISTRY: Registry = Registry::new();
pub static ref PLAY_COUNTER: IntCounter =
register_int_counter!("play_cmd", "Number of calls to /play").unwrap();
pub static ref UPLOAD_COUNTER: IntCounter =
register_int_counter!("upload_cmd", "Number of calls to /upload").unwrap();
pub static ref DELETE_COUNTER: IntCounter =
register_int_counter!("delete_cmd", "Number of calls to /delete").unwrap();
register_int_counter!("play", "Number of calls to /play").unwrap();
}
pub fn init_metrics() {