コード例 #1
0
        public async Task Whois(string user)
        {
            if (Limiter.Limit(Context, TimeSpan.FromSeconds(3)))
            {
                if (Expression.IsMatch(user))
                {
                    ulong discordId   = DsUtils.GetMentionId(user);
                    var   discordUser = await Garden.TheFriendTree.GetUserAsync(discordId);

                    var treeUser = Garden.Tree.GetUser(discordId);

                    if (treeUser == null)
                    {
                        await ReplyAsync($"The target user is not valid in this context!");
                    }
                    else
                    {
                        await ReplyAsync(embed : GetEmbed(discordUser, treeUser, Garden.Tree.GetUser(Context.User.Id)));
                    }
                }
                else
                {
                    await ReplyAsync("Please tag a user!");
                }
            }
        }
コード例 #2
0
            public void CallWithNumber_SetCountReturnObject()
            {
                var     limiter  = new Limiter();
                Limiter returned = limiter.Limit(10);

                limiter.Count.Should().Be(10);
                returned.Should().Be(limiter);
            }
コード例 #3
0
            public void CallWithNumber_SetCountReturnObject()
            {
                var limiter = new Limiter();
                Limiter returned = limiter.Limit(10);

                limiter.Count.ShouldBeEquivalentTo(10);
                returned.ShouldBeEquivalentTo(limiter);
            }
コード例 #4
0
 public void Transform(Point position, Point previousPosition, double deltaResolution = 1, double deltaRotation = 0)
 {
     if (Map.ZoomLock)
     {
         deltaResolution = 1;
     }
     if (Map.PanLock)
     {
         position = previousPosition;
     }
     _viewport.Transform(position, previousPosition, deltaResolution, deltaRotation);
     Limiter.Limit(_viewport, Map.Resolutions, Map.Envelope);
 }
コード例 #5
0
        double LimitSpeedDueToCurrRideMode(double wantedSpeed)
        {
            if (rideMode == RideMode.Forward)
            {
                Limiter.Limit(ref wantedSpeed, 0.0d, double.MaxValue);
            }
            else
            {
                Limiter.Limit(ref wantedSpeed, double.MinValue, 0.0d);
            }

            return(wantedSpeed);
        }
コード例 #6
0
ファイル: FriendModule.cs プロジェクト: encodeous/gardener
 public async Task Friends()
 {
     if (Limiter.Limit(Context, TimeSpan.FromSeconds(1)))
     {
         var cur = Garden.Tree.GetUser(Context.User.Id);
         if (cur != null)
         {
             await ReplyAsync(embed : GetEmbed(cur));
         }
         else
         {
             await ReplyAsync($"The target user is either a bot or is not your friend!");
         }
     }
 }
コード例 #7
0
        public double Limit(int rate, double duration)
        {
            var limiter = new Limiter(rate);
            var count   = 0;
            var start   = Stopwatch.GetTimestamp();

            while ((Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency < duration)
            {
                limiter.Limit(() => Thread.Sleep(1));
                count++;
            }
            var time = (Stopwatch.GetTimestamp() - start) / (double)Stopwatch.Frequency;
            var freq = count / time;

            //Write($"{count} / {time} => {freq} ({rate})");
            return(freq);
        }
コード例 #8
0
        public async Task Trace(string user, string user2)
        {
            if (Limiter.Limit(Context, TimeSpan.FromSeconds(5)))
            {
                if (DsUtils.IsMention(user))
                {
                    ulong discordId = DsUtils.GetMentionId(user);
                    var   treeUser  = Garden.Tree.GetUser(discordId);

                    await ReplyAsync(embed : GetEmbed(treeUser, Garden.Tree.GetUser(Context.User.Id)));
                }
                else
                {
                    await ReplyAsync("Please tag a user!");
                }
            }
        }
コード例 #9
0
        public void Transform(MPoint position, MPoint previousPosition, double deltaResolution = 1, double deltaRotation = 0)
        {
            if (Map == null || Limiter == null)
            {
                return;
            }

            if (Map.ZoomLock)
            {
                deltaResolution = 1;
            }
            if (Map.PanLock)
            {
                position = previousPosition;
            }
            _viewport.Transform(position, previousPosition, deltaResolution, deltaRotation);
            Limiter.Limit(_viewport, Map.Resolutions, Map.Extent);
        }
コード例 #10
0
ファイル: FriendModule.cs プロジェクト: encodeous/gardener
        public async Task UnFriend(string user)
        {
            if (Limiter.Limit(Context, TimeSpan.FromSeconds(1)))
            {
                if (DsUtils.IsMention(user))
                {
                    ulong discordId   = DsUtils.GetMentionId(user);
                    var   discordUser = await Garden.TheFriendTree.GetUserAsync(discordId);

                    var treeUser = Garden.Tree.GetUser(discordId);

                    var currentTreeUser = Garden.Tree.GetUser(Context.User.Id);

                    if (treeUser != null && treeUser.TreeId != currentTreeUser.TreeId && !discordUser.IsBot)
                    {
                        if (currentTreeUser.Friends.Contains(treeUser.TreeId))
                        {
                            treeUser.Friends.Remove(currentTreeUser.TreeId);
                            currentTreeUser.Friends.Remove(treeUser.TreeId);
                            await ReplyAsync($"You are no longer the friend of {DsUtils.GetDiscordUsername(discordUser.Id)}!");
                        }
                        else
                        {
                            await ReplyAsync($"You are not friends with the person.");
                        }
                    }
                    else
                    {
                        await ReplyAsync($"The target user is not valid in this context!");
                    }
                }
                else
                {
                    await ReplyAsync("Please tag a user!");
                }
            }
        }
コード例 #11
0
 public void Transform(double positionX, double positionY, double previousPositionX, double previousPositionY,
                       double deltaResolution = 1, double deltaRotation = 0)
 {
     _viewport.Transform(positionX, positionY, previousPositionX, previousPositionY, deltaResolution, deltaRotation);
     Limiter.Limit(_viewport, Map.Resolutions, Map.Envelope);
 }
コード例 #12
0
        // V100Plus format: 4 byte message length prefix plus payload of null-terminated strings.
        internal void Send()
        {
            var bytes = strings.ToByteArrayWithLengthPrefix();

            limiter.Limit(() => sendAction(bytes, 0, bytes.Length));
        }
コード例 #13
0
        private void HandleKeyDown(KeyEventArgs key)
        {
            double valToBeSet;

            switch (key.Key)
            {
            case Key.Up:
            case Key.W:
                valToBeSet = Controller.Model.CarInfo.TargetSpeed + SPEED_CHANGE_PER_UP_DOWN_ARR_CLICK;
                Limiter.Limit(ref valToBeSet, MAX_BACKWARD_SPEED_WHEN_DRIVING_ON_GAMEPAD_IN_MPS, MAX_FORWARD_SPEED_WHEN_DRIVING_ON_GAMEPAD_IN_MPS);
                valToBeSet = LimitSpeedDueToCurrRideMode(valToBeSet);
                Controller.SetTargetSpeed(valToBeSet);
                break;

            case Key.Down:
            case Key.S:
                valToBeSet = Controller.Model.CarInfo.TargetSpeed - SPEED_CHANGE_PER_UP_DOWN_ARR_CLICK;
                Limiter.Limit(ref valToBeSet, MAX_BACKWARD_SPEED_WHEN_DRIVING_ON_GAMEPAD_IN_MPS, MAX_FORWARD_SPEED_WHEN_DRIVING_ON_GAMEPAD_IN_MPS);
                valToBeSet = LimitSpeedDueToCurrRideMode(valToBeSet);
                Controller.SetTargetSpeed(valToBeSet);
                break;

            case Key.Left:
            case Key.A:
                valToBeSet = Controller.Model.CarInfo.TargetWheelAngle - WHEEL_ANGLE_CHANGE_PER_LEFT_RIGHT_ARR_CLICK;
                Limiter.Limit(ref valToBeSet, -1 * MAX_WHEEL_ANGLE_VALEUE_WHEN_DRIVING_ON_GAMEPAD, MAX_WHEEL_ANGLE_VALEUE_WHEN_DRIVING_ON_GAMEPAD);
                Controller.SetTargetWheelAngle(valToBeSet);
                break;

            case Key.Right:
            case Key.D:
                valToBeSet = Controller.Model.CarInfo.TargetWheelAngle + WHEEL_ANGLE_CHANGE_PER_LEFT_RIGHT_ARR_CLICK;
                Limiter.Limit(ref valToBeSet, -1 * MAX_WHEEL_ANGLE_VALEUE_WHEN_DRIVING_ON_GAMEPAD, MAX_WHEEL_ANGLE_VALEUE_WHEN_DRIVING_ON_GAMEPAD);
                Controller.SetTargetWheelAngle(valToBeSet);
                break;

            case Key.Escape:
                Controller.AlertBrake();
                break;

            case Key.Space:
                Controller.OverrideTargetBrakeSetting(TARGET_BRAKE_SETTING_WHEN_MANUAL_BRAKING_ON);
                brakingTimer.Interval = BRAKE_ACTIVATION_TIME_ON_SPACE_PRESSING_IN_MS;
                brakingTimer.Start();
                break;

            case Key.Q:
                Controller.OverrideTargetBrakeSetting(-80);
                brakingTimer.Interval = BRAKE_ACTIVATION_TIME_ON_SPACE_PRESSING_IN_MS;
                brakingTimer.Start();
                break;

            case Key.K:     //K -> change road direction
                if (rideMode == RideMode.Forward)
                {
                    rideMode = RideMode.Backward;
                }
                else
                {
                    rideMode = RideMode.Forward;
                }
                Controller.SetTargetSpeed(0.0);
                break;

            case Key.Enter:     //Enter -> set wheel to middles
                Controller.SetTargetWheelAngle(0.0);
                break;
            }
        }