コード例 #1
0
        public TimeSpan GetTimePlayedBySound(SoundboardEffect effect)
        {
            var sound = GetSound(effect);

            if (sound != null)
            {
                return(TimeSpan.FromMilliseconds(
                           Convert.ToDouble(sound.Duration * sound.PlayCount)));
            }

            return(TimeSpan.Zero);
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public void Remove(SoundboardEffect effect)
 {
     this.Effects.Add(effect.Name, effect);
 }