예제 #1
0
        public void Execute(ChannelCollection channels)
        {
            if (Password == null || Channel == null || Command == null)
            {
                return;
            }

            if (Password == CommandPassword)
            {
                var channel = channels.FirstOrDefault(c => c.Name == Channel);
                if (channel == null)
                {
                    Log.Warning("Received a command from a channel you aren't in, ignoring.");
                    return;
                }

                if (CheckChannelPermissions(channel))
                {
                    if (Command.Equals("Resume"))
                    {
                        Log.Informational($"Executing Command: {Command}");
                        Program.Unpause();
                    }
                    else if (Command.Equals("Pause"))
                    {
                        Log.Informational($"Executing Command: {Command}");
                        Program.Pause();
                        Program.KillMiner();
                    }
                    else if (Command.Equals("Restart"))
                    {
                        Program.Pause();
                        Log.Informational($"Executing Command: {Command}");
                        Program.KillMiner();
                        Program.Unpause();
                    }
                    else
                    {
                        var cmd = CustomCommands.FirstOrDefault(c => WhitespaceRegex.Replace(c, string.Empty).Equals(Command));

                        if (cmd == null)
                        {
                            Log.Warning($"Received command {Command} but no CustomCommand matching that name exists, ignoring.");
                        }
                        else
                        {
                            Log.Informational($"Executing Command: {Command}");
                            Process.Start($"CustomCommands\\{cmd}.bat");
                        }
                    }
                }
                else
                {
                    Log.Warning($"Received command {Command} but the channel is not marked as Trusted, ignoring.");
                }
            }
            else
            {
                Log.Warning($"Received {Command} command, but the password provided was incorrect. Ignoring the command.");
            }
        }