public TimeSpan GetTimePlayedBySound(SoundboardEffect effect) { var sound = GetSound(effect); if (sound != null) { return(TimeSpan.FromMilliseconds( Convert.ToDouble(sound.Duration * sound.PlayCount))); } return(TimeSpan.Zero); }
/// <summary> /// Records statistics when a user plays a sound. /// </summary> /// <param name="user">Discord user</param> /// <param name="effect">Effect name</param> public void Play(Discord.User profile, SoundboardEffect effect) { var sound = GetSound(effect); var user = GetUser(profile); if (sound != null) { sound.PlayCount++; } if (user != null) { user.MillisecondsPlayed += Convert.ToUInt64(effect.Duration.TotalMilliseconds); } }
private Data.Sound GetSound(SoundboardEffect effect) { var query = from s in Database.Sounds where s.Name == effect.Name select s; var sound = query.FirstOrDefault(); if (sound == null) { sound = new Data.Sound() { Name = effect.Name, Duration = Convert.ToInt32(effect.Duration.TotalMilliseconds), PlayCount = 0 }; Database.Sounds.Add(sound); } return(sound); }
public void Remove(SoundboardEffect effect) { this.Effects.Add(effect.Name, effect); }