Ejemplo n.º 1
0
        public void Execute(string arg)
        {
            if (parent.Status == null)
            {
                return;
            }
            string[] args = Regex.Split(arg.ToLowerInvariant(), " ");
            if (args.Length == 0)
            {
                Out.Log(API.LogType.Warning, $"No command given"); return;
            }
            switch (args[0])
            {
            // Single commands
            case "playpause":
                parent.PlayPause();
                return;

            case "play":
                parent.Play();
                return;

            case "pause":
                parent.Pause();
                return;

            case "next":
                parent.Next();
                return;

            case "previous":
                parent.Previous(skipThreshold);
                return;
            }

            if (args.Length < 2)
            {
                Out.Log(API.LogType.Warning, $"Invalid amount of arguments for {args[9]}"); return;
            }
            switch (args[0])
            {
            // Double commands
            case "volume":
                if (!Int32.TryParse(args[1], out int volume) && volume > 100 && volume < 0)
                {
                    Out.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be an integer between 0 and 100.");
                    return;
                }
                parent.SetVolume(volume);
                return;

            case "seek":
                if (!Int32.TryParse(args[1], out int positionMs))
                {
                    Out.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be an integer.");
                    return;
                }
                parent.Seek(positionMs);
                return;

            case "seekpercent":
            case "setposition":
                if (!float.TryParse(args[1], out float position))
                {
                    Out.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be a number from 0 to 100.");
                    return;
                }
                // TODO probably not correct
                parent.Seek((int)(parent.Status.Item.DurationMs * position) / 100);
                return;

            case "shuffle":
            case "setshuffle":
                if (!ShuffleTryParse(args[1], out bool shuffle))
                {
                    Out.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be either -1, 0, 1, True or False");
                    return;
                }
                parent.SetShuffle(shuffle);
                return;

            case "repeat":
            case "setrepeat":
                if (!RepeatTryParse(args[1], out RepeatState repeat))
                {
                    Out.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be either Off, Track, Context, -1, 0, 1 or 2");
                    return;
                }
                parent.SetRepeat(repeat);
                return;

            default:
                Out.Log(API.LogType.Warning, $"Unknown command: {arg}");
                break;
            }
        }
Ejemplo n.º 2
0
        internal void ExecuteBang(string arg)
        {
            // TODO Cheater
            Thread t = new Thread(() =>
            {
                // TODO Really?
                try
                {
                    parent.CheckAuthentication();

                    string[] args = Regex.Split(arg.ToLowerInvariant(), " ");
                    switch (args[0])
                    {
                    // Single commands
                    case "playpause":
                        parent.PlayPause();
                        return;

                    case "play":
                        parent.Play();
                        return;

                    case "pause":
                        parent.Pause();
                        return;

                    case "next":
                        parent.Next();
                        return;

                    case "previous":
                        parent.Previous(skipThreshold);
                        return;

                    // Double commands
                    case "volume":
                        if (!Int32.TryParse(args[1], out int volume) && volume > 100 && volume < 0)
                        {
                            API.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be an integer between 0 and 100.");
                            return;
                        }
                        parent.SetVolume(volume);
                        return;

                    case "seek":
                        if (!Int32.TryParse(args[1], out int positionS))
                        {
                            API.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be an integer.");
                            return;
                        }
                        parent.Seek(positionS * 1000);
                        return;

                    case "seekpercent":
                    case "setposition":
                        if (!float.TryParse(args[1], out float position))
                        {
                            API.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be a number from 0 to 100.");
                            return;
                        }
                        // TODO error 405
                        parent.Seek((int)(parent.Status.Track.Length * position) / 100);
                        return;

                    case "shuffle":
                    case "setshuffle":
                        if (!ShuffleTryParse(args[1], out bool shuffle))
                        {
                            API.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be either -1, 0, 1, True or False");
                            return;
                        }
                        parent.SetShuffle(shuffle);
                        return;

                    case "repeat":
                    case "setrepeat":
                        if (!RepeatTryParse(args[1], out RepeatState repeat))
                        {
                            API.Log(API.LogType.Warning, $"Invalid arguments for command: {args[0]}. {args[1]} should be either Off, Track, Context, -1, 0, 1 or 2");
                            return;
                        }
                        parent.SetRepeat(repeat);
                        return;

                    default:
                        API.Log(API.LogType.Warning, $"Unknown command: {arg}");
                        break;
                    }
                }
                catch (Exception e)
                {
                    API.Log(API.LogType.Error, $"{e.Message} \n {e.StackTrace}");
                }
            });

            t.Start();
        }