From e0a9b18f45858829f88cbe20611aaf696fc5bf6a Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 22:35:46 -0400 Subject: restore support for volume commands --- src/util/mod.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/util') diff --git a/src/util/mod.rs b/src/util/mod.rs index 38f4e55..474d36d 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,19 +1,9 @@ use std::{ - cmp::max_by, collections::HashMap, - process::{ - id, - Stdio, - }, + process::Stdio, }; -use anyhow::anyhow; use chrono::Duration; -use diesel::row::NamedRow; -use fnv::{ - FnvHashMap, - FnvHashSet, -}; use grate::tracing; use lazy_static::lazy_static; use poise::{ @@ -26,7 +16,6 @@ use regex::{ }; use serenity::{ all::{ - ChannelType, CreateMessage, GuildId, GuildRef, @@ -83,9 +72,9 @@ pub async fn users_listening(ctx: PoiseContext<'_>) -> anyhow::Result { pub fn msg(ctx: poise::Context<'_, U, E>) -> Option<&Message> { match ctx { poise::Context::Prefix(poise::PrefixContext { - msg, - .. - }) => Some(msg), + msg, + .. + }) => Some(msg), _ => None, } } @@ -125,6 +114,18 @@ pub fn unwrap_tts(ctx: poise::Context<'_, U, E>) -> bool { tts(ctx).unwrap_or(false) } +#[inline] +pub async fn volume(ctx: PoiseContext<'_>) -> f64 { + let Some(guild_id) = ctx.guild_id() else { + return 1.; + }; + + let data = ctx.serenity_context().data.read().await; + let vol = data.get::().unwrap(); + + vol.get(&guild_id).map(|g| *g).unwrap_or(1.) +} + #[inline] pub async fn send( ctx: &Context, -- cgit v1.3.1