Example #1
0
        internal static async Task <bool> CheckUserTimeout(SocketUser usr, ulong guildID, IMessageChannel channel)
        {
            var Tracker = UserTimeouts.SingleOrDefault(ut => ut.TrackedUser == usr && ut.GuildID == guildID);

            if (Tracker != null)
            {
                TimeoutTimer t   = UserTimeoutTimers.SingleOrDefault(p => p.Tracker == Tracker);
                var          msg = await channel.SendMessageAsync($"Slow down {usr.Username}! Try again in {TimeSpan.FromSeconds((int)Constants._CMDTIMEOUT_ - (DateTime.Now - t.StartTime).TotalSeconds).Seconds}.{(TimeSpan.FromSeconds(5 - (DateTime.Now - t.StartTime).TotalSeconds).Milliseconds) / 100} seconds.");

                AddRandomTracker((RestUserMessage)msg);
                return(false);
            }
            return(true);
        }
Example #2
0
        internal static void AddUserTimeout(SocketUser usr, ulong guildID)
        {
            var          track  = new TimeoutTracker(usr, guildID);
            TimeoutTimer tTimer = null;
            Timer        t      = new Timer();

            void handler(object sender, ElapsedEventArgs e)
            {
                t.Stop();
                if (UserTimeouts.Contains(track))
                {
                    UserTimeouts.Remove(track);
                    UserTimeoutTimers.Remove(tTimer);
                }
            }

            t.StartTimer(handler, (int)(Constants._CMDTIMEOUT_ * 1000));
            tTimer = new TimeoutTimer(track);
            UserTimeouts.Add(track);
            UserTimeoutTimers.Add(tTimer);
        }