Пример #1
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            if (args == null)
            {
                this.CommandResult.Exit = true;
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #2
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            if (args == null)
            {
                CommandResult.ClearScreen = true;
                CommandResult.DeactivateContext();
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #3
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            bool matchFound = false;

            if (args != null)
            {
                try
                {
                    var extra = options.Parse(args);
                    matchFound = args.Length != extra.Count;
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }

            if (!matchFound)
            {
                if (args.IsNullOrEmpty())
                {
                    CommandResult.WriteLine("You must supply a username.");
                }
                else if (args.Length == 1)
                {
                    var username = args[0];
                    if (!_dataBucket.UserRepository.CheckUserExists(username))
                    {
                        var    random = new Random();
                        string code   = random.Next(1 << 16).ToString("X4")
                                        + random.Next(1 << 16).ToString("X4")
                                        + random.Next(1 << 16).ToString("X4")
                                        + random.Next(1 << 16).ToString("X4");
                        var inviteCode = new InviteCode
                        {
                            Code     = code,
                            Username = username
                        };
                        _dataBucket.InviteCodeRepository.AddInviteCode(inviteCode);
                        _dataBucket.SaveChanges();
                        CommandResult.WriteLine("Invite Code: {0}", code);
                    }
                    else
                    {
                        CommandResult.WriteLine("That username already exists.");
                    }
                }
            }
        }
Пример #4
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            if (args == null)
            {
                CommandResult.ScrollToBottom = false;
                CommandResult.DeactivateContext();
                CommandResult.ClearScreen = true;
                CommandResult.WriteLine(DisplayMode.Inverted, "Available Discussion Boards");
                var boards = _dataBucket.BoardRepository.GetBoards(CommandResult.UserLoggedAndModOrAdmin());
                foreach (var board in boards.ToList())
                {
                    CommandResult.WriteLine();
                    var displayMode = DisplayMode.DontType;
                    if (board.ModsOnly || board.Hidden)
                    {
                        displayMode |= DisplayMode.Dim;
                    }
                    long topicCount = board.BoardID == 0
                        ? _dataBucket.TopicRepository.AllTopicsCount(CommandResult.UserLoggedAndModOrAdmin())
                        : board.TopicCount(CommandResult.UserLoggedAndModOrAdmin());
                    CommandResult.WriteLine(displayMode, "{{[transmit=BOARD]{0}[/transmit]}} {1}{2}{3}{4} | {5} topics",
                                            board.BoardID,
                                            board.Hidden ? "[HIDDEN] " : string.Empty,
                                            board.ModsOnly ? "[MODSONLY] " : string.Empty,
                                            board.Locked ? "[LOCKED] " : string.Empty,
                                            board.Name,
                                            topicCount);
                    if (!board.Description.IsNullOrEmpty())
                    {
                        CommandResult.WriteLine(displayMode, "{0}", board.Description);
                    }
                }
                if (boards.Count() == 0)
                {
                    CommandResult.WriteLine("There are no discussion boards.");
                }
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #5
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            bool matchFound = false;

            if (args != null)
            {
                try
                {
                    var extra = options.Parse(args);
                    matchFound = args.Length != extra.Count;
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }

            if (!matchFound)
            {
                if (args.IsNullOrEmpty())
                {
                    CommandResult.WriteLine("Enter your username.");
                    CommandResult.SetContext(ContextStatus.Forced, Name, args, "Username");
                }
                else if (args.Length == 1)
                {
                    CommandResult.WriteLine("Enter your password.");
                    CommandResult.PasswordField = true;
                    CommandResult.SetContext(ContextStatus.Forced, Name, args, "Password");
                }
                else if (args.Length == 2)
                {
                    var user = _dataBucket.UserRepository.GetUser(args[0]);
                    if (user != null && args[1] == user.Password)
                    {
                        CommandResult.CurrentUser = user;
                        CommandResult.WriteLine("You are now logged in as {0}.", CommandResult.CurrentUser.Username);
                    }
                    else
                    {
                        CommandResult.WriteLine("Invalid username or password.");
                    }
                    if (CommandResult.CommandContext.Status == ContextStatus.Forced)
                    {
                        CommandResult.RestoreContext();
                    }
                }
            }
        }
Пример #6
0
            bool IMessageFilter.PreFilterMessage(ref Message m)
            {
                // Use a switch so we can trap other messages in the future
                switch (m.Msg)
                {
                case 0x100:     // WM_KEYDOWN

                    if ((int)m.WParam == (int)Keys.F1)
                    {
                        HelpUtility.ProcessHelpRequest(Control.FromHandle(m.HWnd));
                        return(true);
                    }
                    break;
                }
                return(false);
            }
Пример #7
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            bool matchFound = false;

            if (args != null)
            {
                try
                {
                    var extra = options.Parse(args);
                    matchFound = args.Length != extra.Count;
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }

            if (!matchFound)
            {
                if (args.IsNullOrEmpty())
                {
                    this.CommandResult.CurrentUser.LastLogin = DateTime.UtcNow.AddMinutes(-10);
                    _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                    this.CommandResult.WriteLine("You have been logged out.");
                    this.CommandResult.CommandContext.Deactivate();
                    this.CommandResult.CurrentUser = null;
                }
            }
        }
Пример #8
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            if (args == null)
            {
                if (CommandResult.CurrentUser == null)
                {
                    CommandResult.DeactivateContext();
                    //var lines = AppSettings.Logo.Split('\n');
                    //foreach (var line in lines)
                    //{
                    //    CommandResult.WriteLine(DisplayMode.DontWrap, line);
                    //}
                    //CommandResult.WriteLine();
                    CommandResult.WriteLine(DisplayMode.Inverted, "OMEGA LOCKDOWN ACTIVE");
                    CommandResult.WriteLine();
                    CommandResult.WriteLine("As per article 21 subsection D of the Omega Directive,");
                    CommandResult.WriteLine("only authorized agents are allowed beyond this point.");
                }
                else
                {
                    CommandResult.WriteLine("You are currently logged in as {0}.", CommandResult.CurrentUser.Username);
                }
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #9
0
        public static void PrintHelp()
        {
            ConsoleHelper.LogLevel = LogLevel.Trace; // Show all messages
            HelpUtility.PrintParameterHelp(ParametersToShowHelpFor);
            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("==== General Instructions ====", foregroundColor: ConsoleColor.DarkCyan);
            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("This is a command line tool to upload all web resources from a folder to a CRM instance. It discovers all files with valid web resource file extensions. Initially, you should use this from a console. As long as you don't use /automate or /force, this is perfectly safe, and will explain which actions it wishes to perform, followed by a prompt whether to continue or not. Feel free to experiment with the optional parameters in this mode. Example usage (line breaks should naturally be omitted):", indent: 1);
            ConsoleHelper.WriteLine();

            ConsoleHelper.Write("CrmResourceUploader.exe", indent: 1);
            ConsoleHelper.Write("/solutionname:", indent: 1, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("Default");
            ConsoleHelper.Write("/rootpath:", indent: 25, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("\"../../WebResources/build/release\"", wrappedIndent: 29);
            ConsoleHelper.Write("/crmconnectionstring:", indent: 25, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("'Url=https://contoso.crm2.dynamics.com/Contoso; [email protected]; Password=password'", wrappedIndent: 29);
            ConsoleHelper.WriteLine("/nonew /nopublish", indent: 25, foregroundColor: ConsoleColor.Magenta);

            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("Once you are happy with your options, you can save them (in, say, a batch file) for running automatically. You should add /automate or /force to ensure the tool proceeds without interruption.", indent: 1);
            ConsoleHelper.WriteLine();
        }
Пример #10
0
        public static void PrintHelp()
        {
            ConsoleHelper.LogLevel = LogLevel.Trace; // Show all messages
            HelpUtility.PrintParameterHelp(ParametersToShowHelpFor);
            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("==== General Instructions ====", foregroundColor: ConsoleColor.DarkCyan);
            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("This is a command line tool to upload custom plugin and workflow code from a dll to a CRM instance. The dll should already be registered with the SDK, and the appropriate steps created, this tool is simply for command-line updating. Initially, you should use this from a console. As long as you don't use /automate or /force, this is perfectly safe, and will explain which actions it wishes to perform, followed by a prompt whether to continue or not. Feel free to experiment with the optional parameters in this mode. Example usage (line breaks should naturally be omitted):", indent: 1);
            ConsoleHelper.WriteLine();

            ConsoleHelper.Write("PluginWorkflowHelper.exe", indent: 1);
            ConsoleHelper.Write("/solutionname:", indent: 1, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("Default");
            ConsoleHelper.Write("/dllpath:", indent: 25, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("\"../../DotNet/bin/Release/CrmPlugins.dll\"", wrappedIndent: 29);
            ConsoleHelper.Write("/crmconnectionstring:", indent: 25, foregroundColor: ConsoleColor.Yellow);
            ConsoleHelper.WriteLine("'Url=https://contoso.crm2.dynamics.com/Contoso; [email protected]; Password=password'", wrappedIndent: 29);
            ConsoleHelper.WriteLine("/nonew", indent: 25, foregroundColor: ConsoleColor.Magenta);

            ConsoleHelper.WriteLine();
            ConsoleHelper.WriteLine("Once you are happy with your options, you can save them (in, say, a batch file) for running automatically. You should add /automate or /force to ensure the tool proceeds without interruption.", indent: 1);
            ConsoleHelper.WriteLine();
        }
Пример #11
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            bool matchFound = false;

            if (args != null)
            {
                try
                {
                    var extra = options.Parse(args);
                    matchFound = args.Length != extra.Count;
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }

            if (!matchFound)
            {
                if (args.IsNullOrEmpty())
                {
                    CommandResult.CurrentUser.LastLogin = DateTime.UtcNow.AddMinutes(-10);
                    _dataBucket.UserRepository.UpdateUser(CommandResult.CurrentUser);
                    _dataBucket.SaveChanges();
                    CommandResult.WriteLine("You have been logged out.");
                    CommandResult.CurrentUser = null;
                }
            }
        }
Пример #12
0
        public void Invoke(string[] args)
        {
            bool  showHelp          = false;
            bool  replyToTopic      = false;
            bool  refresh           = false;
            bool  edit              = false;
            bool  delete            = false;
            bool  report            = false;
            bool  modReply          = false;
            bool? lockTopic         = null;
            bool? stickyTopic       = null;
            bool? globalStickyTopic = null;
            long? replyId           = null;
            short?moveToBoard       = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "r|reply",
                "Reply to the topic.",
                x => replyToTopic = x != null
                );
            options.Add(
                "R|refresh",
                "Refresh the current topic.",
                x => refresh = x != null
                );
            options.Add(
                "e|edit:",
                "Edits the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                edit = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );
            options.Add(
                "d|delete:",
                "Deletes the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                delete = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );
            options.Add(
                "report:",
                "Report abuse for the topic or a reply if a {ReplyID} is specified.",
                x =>
            {
                report = true;
                if (x.IsLong())
                {
                    replyId = x.ToLong();
                }
            }
                );

            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "mr|modReply",
                    "A reply only moderators can see.",
                    x =>
                {
                    modReply     = x != null;
                    replyToTopic = x != null;
                }
                    );
                options.Add(
                    "l|lock",
                    "Locks the topic preventing further replies except modreplies.",
                    x => lockTopic = x != null
                    );
                options.Add(
                    "s|sticky",
                    "Sticky's the topic keeping it at the top of the board regardless of last reply date.",
                    x => stickyTopic = x != null
                    );
                options.Add(
                    "g|globalSticky",
                    "Sticky's the topic keeping it at the top of \"All Activity Board\".",
                    x => globalStickyTopic = x != null
                    );
                options.Add(
                    "m|move=",
                    "Moves the topic to the board with the specified {BoardID}.",
                    x => moveToBoard = x.ToShort()
                    );
            }

            try
            {
                if (args == null)
                {
                    this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                }
                else
                {
                    var parsedArgs = options.Parse(args).ToArray();
                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            if (parsedArgs[0].IsLong())
                            {
                                var topicId     = parsedArgs[0].ToLong();
                                var page        = 1;
                                var topic       = _topicRepository.GetTopic(topicId);
                                var isAnonymous = _boardRepository.GetBoard(topic.BoardID).Anonymous;
                                if (topic != null)
                                {
                                    if (topic.ModsOnly)
                                    {
                                        if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            WriteTopic(topicId, page);
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("You do not have permission to view this topic.");
                                        }
                                    }
                                    else
                                    {
                                        WriteTopic(topicId, page);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                            }
                        }
                        else if (parsedArgs.Length == 2)
                        {
                            if (parsedArgs[0].IsInt())
                            {
                                var topicId = parsedArgs[0].ToLong();
                                if (parsedArgs[1].IsInt())
                                {
                                    var page        = parsedArgs[1].ToInt();
                                    var topic       = _topicRepository.GetTopic(topicId);
                                    var isAnonymous = _boardRepository.GetBoard(topic.BoardID).Anonymous;
                                    if (topic != null)
                                    {
                                        if (topic.ModsOnly)
                                        {
                                            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                WriteTopic(topicId, page);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You do not have permission to view this topic.");
                                            }
                                        }
                                        else
                                        {
                                            WriteTopic(topicId, page);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else if (PagingUtility.Shortcuts.Any(x => parsedArgs[1].Is(x)))
                                {
                                    var page = PagingUtility.TranslateShortcut(parsedArgs[1], this.CommandResult.CommandContext.CurrentPage);
                                    WriteTopic(topicId, page);
                                    if (parsedArgs[1].Is("last") || parsedArgs[1].Is("prev"))
                                    {
                                        this.CommandResult.ScrollToBottom = true;
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid page number.", parsedArgs[1]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (replyToTopic)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    var topic   = _topicRepository.GetTopic(topicId);
                                    if (topic != null)
                                    {
                                        if (!topic.Locked || (!topic.IsModsOnly() && modReply && this.CommandResult.CurrentUser.IsModerator) || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (this.CommandResult.CommandContext.PromptData == null)
                                                {
                                                    this.CommandResult.WriteLine("Type your reply.");
                                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} REPLY", topicId));
                                                }
                                                else
                                                {
                                                    _replyRepository.AddReply(new Reply
                                                    {
                                                        Username   = this.CommandResult.CurrentUser.Username,
                                                        PostedDate = DateTime.UtcNow,
                                                        LastEdit   = DateTime.UtcNow,
                                                        TopicID    = topicId,
                                                        Body       = BBCodeUtility.SimplifyComplexTags(
                                                            this.CommandResult.CommandContext.PromptData[0],
                                                            _replyRepository,
                                                            this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                            ),
                                                        ModsOnly = modReply && !topic.IsModsOnly()
                                                    });
                                                    this.CommandResult.CommandContext.PromptData = null;
                                                    var TOPIC = this.AvailableCommands.SingleOrDefault(x => x.Name.Is("TOPIC"));
                                                    TOPIC.Invoke(new string[] { topicId.ToString(), "last" });
                                                    this.CommandResult.WriteLine("Reply successfully posted.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is for moderators only.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (edit)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    if (replyId == null)
                                    {
                                        var topic = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (topic.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                    (this.CommandResult.CurrentUser.IsModerator && !topic.IsModsOnly() && !topic.User.IsModerator && !topic.User.IsAdministrator) ||
                                                    this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (this.CommandResult.CommandContext.PromptData == null)
                                                    {
                                                        this.CommandResult.WriteLine("Edit the topic title.");
                                                        this.CommandResult.EditText = topic.Title;
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Title", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                    {
                                                        this.CommandResult.WriteLine("Edit the topic body.");
                                                        this.CommandResult.EditText = topic.Body;
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Body", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                                                    {
                                                        topic.Title = this.CommandResult.CommandContext.PromptData[0];
                                                        topic.Body  = BBCodeUtility.SimplifyComplexTags(
                                                            this.CommandResult.CommandContext.PromptData[1],
                                                            _replyRepository,
                                                            this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                            );
                                                        topic.LastEdit = DateTime.UtcNow;
                                                        topic.EditedBy = this.CommandResult.CurrentUser.Username;
                                                        _topicRepository.UpdateTopic(topic);
                                                        this.CommandResult.CommandContext.PromptData = null;
                                                        this.CommandResult.WriteLine("Topic '{0}' was edited successfully.", topicId);
                                                        this.CommandResult.CommandContext.Restore();
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' belongs to '{1}'. You are not authorized to edit it.", topicId, topic.Username);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        var reply = _replyRepository.GetReply((long)replyId);
                                        if (reply != null)
                                        {
                                            if (reply.TopicID == topicId)
                                            {
                                                if (!reply.Topic.Locked || (reply.ModsOnly && !reply.Topic.IsModsOnly()) || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (reply.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                        (this.CommandResult.CurrentUser.IsModerator && !reply.IsModsOnly() && !reply.User.IsModerator && !reply.User.IsAdministrator) ||
                                                        this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        if (this.CommandResult.CommandContext.PromptData == null)
                                                        {
                                                            this.CommandResult.WriteLine("Edit the reply body.");
                                                            this.CommandResult.EditText = reply.Body;
                                                            this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} EDIT Reply {1}", topicId, replyId));
                                                        }
                                                        else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                        {
                                                            reply.Body = BBCodeUtility.SimplifyComplexTags(
                                                                this.CommandResult.CommandContext.PromptData[0],
                                                                _replyRepository,
                                                                this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                                );
                                                            reply.LastEdit = DateTime.UtcNow;
                                                            reply.EditedBy = this.CommandResult.CurrentUser.Username;
                                                            _replyRepository.UpdateReply(reply);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            this.CommandResult.WriteLine("Reply '{0}' was edited successfully.", replyId);
                                                            this.CommandResult.CommandContext.Restore();
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("Reply '{0}' belongs to '{1}'. You are not authorized to edit it.", replyId, reply.Username);
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' does not contain a reply with ID '{1}'.", topicId, replyId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Reply '{0}' does not exist.", replyId);
                                        }
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (delete)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var topicId = parsedArgs[0].ToLong();
                                    if (replyId == null)
                                    {
                                        var topic = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (this.CommandResult.CommandContext.PromptData == null)
                                                    {
                                                        this.CommandResult.WriteLine("Are you sure you want to delete the topic titled \"{0}\"? (Y/N)", topic.Title);
                                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} DELETE CONFIRM", topicId));
                                                    }
                                                    else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                    {
                                                        if (this.CommandResult.CommandContext.PromptData[0].Is("Y"))
                                                        {
                                                            _topicRepository.DeleteTopic(topic);
                                                            this.CommandResult.WriteLine("Topic '{0}' was deleted successfully.", topicId);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            if (this.CommandResult.CommandContext.PreviousContext != null &&
                                                                this.CommandResult.CommandContext.PreviousContext.Command.Is("TOPIC") &&
                                                                this.CommandResult.CommandContext.PreviousContext.Args.Contains(topicId.ToString()) &&
                                                                this.CommandResult.CommandContext.PreviousContext.Status == ContextStatus.Passive)
                                                            {
                                                                this.CommandResult.ClearScreen = true;
                                                                this.CommandResult.CommandContext.Deactivate();
                                                            }
                                                            else
                                                            {
                                                                this.CommandResult.CommandContext.Restore();
                                                            }
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("Topic '{0}' was not deleted.", topicId);
                                                            this.CommandResult.CommandContext.PromptData = null;
                                                            this.CommandResult.CommandContext.Restore();
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("You are not an administrator. You are not authorized to delete topics.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID {0}.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        var reply = _replyRepository.GetReply((long)replyId);
                                        if (reply != null)
                                        {
                                            if (reply.TopicID == topicId)
                                            {
                                                if (!reply.Topic.Locked || (reply.ModsOnly && !reply.Topic.IsModsOnly()) || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (reply.Username.Is(this.CommandResult.CurrentUser.Username) ||
                                                        (this.CommandResult.CurrentUser.IsModerator && !reply.IsModsOnly() && !reply.User.IsModerator && !reply.User.IsAdministrator) ||
                                                        this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        _replyRepository.DeleteReply(reply);
                                                        this.CommandResult.WriteLine("Reply '{0}' was deleted successfully.", replyId);
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("Reply '{0}' belongs to '{1}'. You are not authorized to delete it.", replyId, reply.Username);
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Topic '{0}' is locked.", topicId);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Topic '{0}' does not contain a reply with ID '{1}'.", topicId, replyId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Reply '{0}' does not exist.", replyId);
                                        }
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a topic ID.");
                            }
                        }
                        else if (report)
                        {
                            // allow user to report abuse.
                        }
                        else
                        {
                            if (lockTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if ((bool)lockTopic || (!(bool)lockTopic && this.CommandResult.CurrentUser.IsAdministrator))
                                                {
                                                    topic.Locked = (bool)lockTopic;
                                                    _topicRepository.UpdateTopic(topic);
                                                    string status = (bool)lockTopic ? "locked" : "unlocked";
                                                    this.CommandResult.WriteLine("Topic '{0}' was successfully {1}.", topicId, status);
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Only administrators can unlock topics.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to lock moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID {0}.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (stickyTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                topic.Stickied = (bool)stickyTopic;
                                                _topicRepository.UpdateTopic(topic);
                                                string status = (bool)stickyTopic ? "stickied" : "unstickied";
                                                this.CommandResult.WriteLine("Topic '{0}' was successfully {1}.", topicId, status);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to sticky/unsticky moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (globalStickyTopic != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                topic.GlobalSticky = (bool)globalStickyTopic;
                                                _topicRepository.UpdateTopic(topic);
                                                string status = (bool)globalStickyTopic ? "stickied" : "unstickied";
                                                this.CommandResult.WriteLine("Topic '{0}' was successfully globally {1}.", topicId, status);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You are not authorized to globally sticky/unsticky moderator topics.");
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                            if (moveToBoard != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        var topic   = _topicRepository.GetTopic(topicId);
                                        if (topic != null)
                                        {
                                            var board = _boardRepository.GetBoard((short)moveToBoard);
                                            if (board != null)
                                            {
                                                if (!board.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                                {
                                                    if (!topic.IsModsOnly() || this.CommandResult.CurrentUser.IsAdministrator)
                                                    {
                                                        if (!board.ModsOnly || this.CommandResult.CurrentUser.IsAdministrator)
                                                        {
                                                            topic.BoardID = (short)moveToBoard;
                                                            _topicRepository.UpdateTopic(topic);
                                                            this.CommandResult.WriteLine("Topic '{0}' was successfully moved to board '{1}'.", topicId, moveToBoard);
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("You are not authorized to move topics onto moderator boards.");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("You are not authorized to move moderator topics.");
                                                    }
                                                }
                                                else
                                                {
                                                    this.CommandResult.WriteLine("Board '{0}' is locked.", moveToBoard);
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("There is no board with ID '{0}'.", moveToBoard);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no topic with ID '{0}'.", topicId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a board ID.");
                                }
                            }
                            if (refresh)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsLong())
                                    {
                                        var topicId = parsedArgs[0].ToLong();
                                        WriteTopic(topicId, this.CommandResult.CommandContext.CurrentPage);
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid topic ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a topic ID.");
                                }
                            }
                        }
                    }
                }
            }
            catch (OptionException ex)
            {
                this.CommandResult.WriteLine(ex.Message);
            }
        }
Пример #13
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            if (args == null)
            {
                if (this.CommandResult.CurrentUser == null)
                {
                    this.CommandResult.CommandContext.Deactivate();
                    this.CommandResult.WriteLine("Welcome to...");
                    this.CommandResult.WriteLine(DisplayMode.DontType | DisplayMode.DontWrap, AppSettings.Logo);
                    if (DateTime.Now.Month == 10)
                    {
                        this.CommandResult.WriteLine(DisplayMode.DontType | DisplayMode.DontWrap, @"
                          .,'
                       .'`.'
                      .' .'
          _.ood0Pp._ ,'  `.~ .q?00doo._
      .od00Pd0000Pdb._. . _:db?000b?000bo.
    .?000Pd0000PP?000PdbMb?000P??000b?0000b.
  .d0000Pd0000P'  `?0Pd000b?0'  `?000b?0000b.
 .d0000Pd0000?'     `?d000b?'     `?00b?0000b.
 d00000Pd0000Pd0000Pd00000b?00000b?0000b?0000b
 ?00000b?0000b?0000b?b    dd00000Pd0000Pd0000P
 `?0000b?0000b?0000b?0b  dPd00000Pd0000Pd000P'
  `?0000b?0000b?0000b?0bd0Pd0000Pd0000Pd000P'
    `?000b?00bo.   `?P'  `?P'   .od0Pd000P'
      `~?00b?000bo._  .db.  _.od000Pd0P~'
          `~?0b?0b?000b?0Pd0Pd000PdP~'");
                        this.CommandResult.WriteLine(DisplayMode.Inverted, "                HAPPY HALLOWEEN!                ");
                    }
                    else if (DateTime.Now.Month == 12)
                    {
                        this.CommandResult.WriteLine(DisplayMode.DontType | DisplayMode.DontWrap, @"
                            |                         _...._
                         \  _  /                    .::o:::::.
                          (\o/)                    .:::'''':o:.
                      ---  / \  ---                :o:_    _:::
                           >*<                     `:)_>()<_(:'
                          >0<@<                 @    `'//\\'`    @ 
                         >>>@<<*              @ #     //  \\     # @
                        >@>*<0<<<           __#_#____/'____'\____#_#__
                       >*>>@<<<@<<         [__________________________]
                      >@>>0<<<*<<@<         |=_- .-/\ /\ /\ /\--. =_-|
                     >*>>0<<@<<<@<<<        |-_= | \ \\ \\ \\ \ |-_=-|
                    >@>>*<<@<>*<<0<*<       |_=-=| / // // // / |_=-_|
      \*/          >0>>*<<@<>0><<*<@<<      |=_- |`-'`-'`-'`-'  |=_=-|
  ___\\U//___     >*>>@><0<<*>>@><*<0<<     | =_-| o          o |_==_| 
  |\\ | | \\|    >@>>0<*<<0>>@<<0<<<*<@<    |=_- | !     (    ! |=-_=|
  | \\| | _(UU)_ >((*))_>0><*<0><@<<<0<*<  _|-,-=| !    ).    ! |-_-=|_
  |\ \| || / //||.*.*.*.|>>@<<*<<@>><0<<@</=-((=_| ! __(:')__ ! |=_==_-\
  |\\_|_|&&_// ||*.*.*.*|_\\db//__     (\_/)-=))-|/^\=^=^^=^=/^\| _=-_-_\
  ''''|'.'.'.|~~|.*.*.*|     ____|_   =('.')=//   ,------------.      
  jgs |'.'.'.|   ^^^^^^|____|>>>>>>|  ( ~~~ )/   (((((((())))))))   
      ~~~~~~~~         '''''`------'  `w---w`     `------------'");
                        this.CommandResult.WriteLine(DisplayMode.Inverted, "                                HAPPY HOLIDAYS!                                ");
                    }
                    this.CommandResult.WriteLine();
                    this.CommandResult.WriteLine("Type 'HELP' to begin.");
                }
                else
                {
                    this.CommandResult.WriteLine("You are currently logged in as {0}.", this.CommandResult.CurrentUser.Username);
                }
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #14
0
        public void Invoke(string[] args)
        {
            bool   showHelp  = false;
            bool   sent      = false;
            bool   refresh   = false;
            bool   deleteAll = false;
            string username  = this.CommandResult.CurrentUser.Username;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "R|refresh",
                "Refresh the current list of messages.",
                x => refresh = x != null
                );
            options.Add(
                "s|sent",
                "Display sent messages.",
                x => sent = x != null
                );
            options.Add(
                "i|inbox",
                "Display received messages.",
                x => sent = x == null
                );
            options.Add(
                "da|deleteAll",
                "Delete all messages, excluding locked messages.",
                x => deleteAll = x != null
                );
            if (this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "u|user="******"Get messages for a specified {Username}.",
                    x => username = x
                    );
            }

            if (args == null)
            {
                WriteMessages(username, 1, false);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            if (parsedArgs[0].IsInt())
                            {
                                var page = parsedArgs[0].ToInt();
                                WriteMessages(username, page, false);
                            }
                            else if (PagingUtility.Shortcuts.Any(x => parsedArgs[0].Is(x)))
                            {
                                var page = PagingUtility.TranslateShortcut(parsedArgs[0], this.CommandResult.CommandContext.CurrentPage);
                                WriteMessages(username, page, false);
                                if (parsedArgs[0].Is("last") || parsedArgs[0].Is("prev"))
                                {
                                    this.CommandResult.ScrollToBottom = false;
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid page number.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (deleteAll)
                        {
                            if (this.CommandResult.CommandContext.PromptData == null)
                            {
                                this.CommandResult.WriteLine("Are you sure you want to delete all {0} messages? (Y/N)", sent ? "sent" : "received");
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("DELETE {0} CONFIRM", sent ? "SENT" : "RECEIVED"));
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                            {
                                if (this.CommandResult.CommandContext.PromptData[0].Is("Y"))
                                {
                                    var messages = _messageRepository.GetAllMessages(username, sent)
                                                   .Where(x => sent ? !x.SenderLocked : !x.RecipientLocked).ToList();
                                    foreach (var message in messages)
                                    {
                                        if (sent)
                                        {
                                            message.SenderDeleted = true;
                                        }
                                        else
                                        {
                                            message.RecipientDeleted = true;
                                        }
                                        _messageRepository.UpdateMessage(message);
                                    }
                                    this.CommandResult.WriteLine("All {0} messages for '{1}' have been deleted.", sent ? "sent" : "received", username);
                                    this.CommandResult.CommandContext.PromptData = null;
                                    this.CommandResult.CommandContext.Restore();
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("{0} messages were not deleted.", sent ? "Sent" : "Received");
                                    this.CommandResult.CommandContext.PromptData = null;
                                    this.CommandResult.CommandContext.Restore();
                                }
                            }
                        }
                        else
                        if (refresh)
                        {
                            WriteMessages(username, this.CommandResult.CommandContext.CurrentPage, sent);
                        }
                        else
                        if (parsedArgs.Length >= 1)
                        {
                            if (parsedArgs[0].IsInt())
                            {
                                var page = parsedArgs[0].ToInt();
                                WriteMessages(username, page, sent);
                            }
                            else if (PagingUtility.Shortcuts.Any(x => parsedArgs[0].Is(x)))
                            {
                                var page = PagingUtility.TranslateShortcut(parsedArgs[0], this.CommandResult.CommandContext.CurrentPage);
                                WriteMessages(username, page, sent);
                                if (parsedArgs[1].Is("last") || parsedArgs[1].Is("prev"))
                                {
                                    this.CommandResult.ScrollToBottom = false;
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid page number.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            WriteMessages(username, 1, sent);
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #15
0
        public void Invoke(string[] args)
        {
            bool   showHelp          = false;
            bool?  ignore            = null;
            bool   warn              = false;
            bool?  ban               = null;
            bool   history           = false;
            string setRole           = null;
            string removeRole        = null;
            string minecraftUsername = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "i|ignore",
                "Ignore the specified user.",
                x => ignore = x != null
                );
            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "h|history",
                    "Show warning & ban history for the user.",
                    x => history = x != null
                    );
                options.Add(
                    "w|warn",
                    "Warn the user about an offense.",
                    x => warn = x != null
                    );
                options.Add(
                    "b|ban",
                    "Ban the user for a specified amount of time.",
                    x => ban = x != null
                    );
            }
            if (this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "setRole=",
                    "Add the specified role to the user.",
                    x => setRole = x
                    );
                options.Add(
                    "removeRole=",
                    "Remove the specified role from the user.",
                    x => removeRole = x
                    );
            }

            if (args == null)
            {
                this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            var user = _userRepository.GetUser(parsedArgs[0]);
                            if (user != null)
                            {
                                // display user profile.
                            }
                            else
                            {
                                this.CommandResult.WriteLine("There is no user with the username '{0}'.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine("You must specify a username.");
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (warn)
                        {
                            if (parsedArgs.Length == 1)
                            {
                                var user = _userRepository.GetUser(parsedArgs[0]);
                                if (user != null)
                                {
                                    if ((!user.IsModerator && !user.IsAdministrator) || this.CommandResult.CurrentUser.IsAdministrator)
                                    {
                                        if (this.CommandResult.CommandContext.PromptData == null)
                                        {
                                            this.CommandResult.WriteLine("Type the details of your warning to '{0}'.", user.Username);
                                            this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} WARNING", user.Username));
                                        }
                                        else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                        {
                                            user.UserActivityLog.Add(new UserActivityLogItem
                                            {
                                                Type        = "Warning",
                                                Date        = DateTime.UtcNow,
                                                Information = string.Format(
                                                    "Warning given by '{0}'\n\nDetails: {1}",
                                                    this.CommandResult.CurrentUser.Username,
                                                    this.CommandResult.CommandContext.PromptData[0]
                                                    )
                                            });
                                            user.ReceivedMessages.Add(new Message
                                            {
                                                Sender   = this.CommandResult.CurrentUser.Username,
                                                SentDate = DateTime.UtcNow,
                                                Subject  = string.Format(
                                                    "{0} has given you a warning.",
                                                    this.CommandResult.CurrentUser.Username
                                                    ),
                                                Body = string.Format(
                                                    "You have been given a warning by '{0}'.\n\n{1}",
                                                    this.CommandResult.CurrentUser.Username,
                                                    this.CommandResult.CommandContext.PromptData[0]
                                                    )
                                            });
                                            _userRepository.UpdateUser(user);
                                            this.CommandResult.CommandContext.Restore();
                                            this.CommandResult.WriteLine("Warning successfully issued to '{0}'.", user.Username);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("You are not authorized to give warnings to user '{0}'.", user.Username);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("There is no user with the username '{0}'.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must specify a username.");
                            }
                        }
                        else if (ban != null)
                        {
                            if (parsedArgs.Length == 1)
                            {
                                var user = _userRepository.GetUser(parsedArgs[0]);
                                if (user != null)
                                {
                                    if ((!user.IsModerator && !user.IsAdministrator) || this.CommandResult.CurrentUser.IsAdministrator)
                                    {
                                        if ((bool)ban)
                                        {
                                            if (user.BanInfo == null)
                                            {
                                                if (this.CommandResult.CommandContext.PromptData == null)
                                                {
                                                    this.CommandResult.WriteLine("How severe should the ban be?");
                                                    this.CommandResult.WriteLine();
                                                    this.CommandResult.WriteLine("1 = One Hour");
                                                    this.CommandResult.WriteLine("2 = Three Hours");
                                                    this.CommandResult.WriteLine("3 = One Day");
                                                    this.CommandResult.WriteLine("4 = One Week");
                                                    this.CommandResult.WriteLine("5 = One Month");
                                                    this.CommandResult.WriteLine("6 = One Year");
                                                    this.CommandResult.WriteLine("7 = 413 Years");
                                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} BAN SEVERITY", user.Username));
                                                }
                                                else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                {
                                                    string promptData = this.CommandResult.CommandContext.PromptData[0];
                                                    if (promptData.IsShort())
                                                    {
                                                        var banType = promptData.ToShort();
                                                        if (banType >= 1 && banType <= 7)
                                                        {
                                                            this.CommandResult.WriteLine("Type a reason for this ban.");
                                                            this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} BAN REASON", user.Username));
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("'{0}' is not a valid ban type.", banType);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("'{0}' is not a valid ban type.", promptData);
                                                    }
                                                }
                                                else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                                                {
                                                    string promptData = this.CommandResult.CommandContext.PromptData[0];
                                                    if (promptData.IsShort())
                                                    {
                                                        var banType = promptData.ToShort();
                                                        if (banType >= 1 && banType <= 7)
                                                        {
                                                            DateTime expirationDate = DateTime.UtcNow;
                                                            switch (banType)
                                                            {
                                                            case 1:
                                                                expirationDate = DateTime.UtcNow.AddHours(1);
                                                                break;

                                                            case 2:
                                                                expirationDate = DateTime.UtcNow.AddHours(3);
                                                                break;

                                                            case 3:
                                                                expirationDate = DateTime.UtcNow.AddDays(1);
                                                                break;

                                                            case 4:
                                                                expirationDate = DateTime.UtcNow.AddDays(7);
                                                                break;

                                                            case 5:
                                                                expirationDate = DateTime.UtcNow.AddMonths(1);
                                                                break;

                                                            case 6:
                                                                expirationDate = DateTime.UtcNow.AddYears(1);
                                                                break;

                                                            case 7:
                                                                expirationDate = DateTime.UtcNow.AddYears(413);
                                                                break;
                                                            }
                                                            user.UserActivityLog.Add(new UserActivityLogItem
                                                            {
                                                                Type        = "Ban",
                                                                Date        = DateTime.UtcNow,
                                                                Information = string.Format(
                                                                    "Ban given by '{0}'\n\nExpiration: {1}\n\nDetails: {2}",
                                                                    this.CommandResult.CurrentUser.Username,
                                                                    expirationDate.TimeUntil(),
                                                                    this.CommandResult.CommandContext.PromptData[1]
                                                                    )
                                                            });
                                                            this.CommandResult.CurrentUser.Banned_Users.Add(new Ban
                                                            {
                                                                StartDate = DateTime.UtcNow,
                                                                EndDate   = expirationDate,
                                                                Username  = user.Username,
                                                                Reason    = this.CommandResult.CommandContext.PromptData[1]
                                                            });
                                                            _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                                            this.CommandResult.CommandContext.Restore();
                                                            this.CommandResult.WriteLine("'{0}' banned successfully.", user.Username);
                                                        }
                                                        else
                                                        {
                                                            this.CommandResult.WriteLine("'{0}' is not a valid ban type.", banType);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        this.CommandResult.WriteLine("'{0}' is not a valid ban type.", promptData);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("User '{0}' is already banned.", user.Username);
                                            }
                                        }
                                        else
                                        {
                                            if (user.BanInfo != null)
                                            {
                                                _userRepository.UnbanUser(user.Username);
                                                _userRepository.UpdateUser(user);
                                                this.CommandResult.WriteLine("User '{0}' successfully unbanned.", user.Username);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("User '{0}' is not banned.", user.Username);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("You are not authorized to ban user '{0}'.", user.Username);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("There is no user with the username '{0}'.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must specify a username.");
                            }
                        }
                        else
                        {
                            if (history)
                            {
                                if (parsedArgs.Length == 1)
                                {
                                    var user = _userRepository.GetUser(parsedArgs[0]);
                                    if (user != null)
                                    {
                                        var offenseLog = _userRepository.GetOffenseHistory(user.Username);
                                        this.CommandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
                                        foreach (var logItem in offenseLog)
                                        {
                                            this.CommandResult.WriteLine();
                                            if (logItem.Type.Is("Ban"))
                                            {
                                                this.CommandResult.WriteLine(DisplayMode.DontType, "'{0}' was banned {1}.", user.Username, logItem.Date.TimePassed());
                                            }
                                            else if (logItem.Type.Is("Warning"))
                                            {
                                                this.CommandResult.WriteLine(DisplayMode.DontType, "'{0}' was warned {1}.", user.Username, logItem.Date.TimePassed());
                                            }
                                            this.CommandResult.WriteLine();
                                            this.CommandResult.WriteLine(DisplayMode.DontType, logItem.Information);
                                            this.CommandResult.WriteLine();
                                            this.CommandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
                                        }
                                        if (offenseLog.Count() == 0)
                                        {
                                            this.CommandResult.WriteLine();
                                            this.CommandResult.WriteLine("User '{0}' does not have any offenses.", user.Username);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no user with the username '{0}'.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must specify a username.");
                                }
                            }
                            if (ignore != null)
                            {
                                if (parsedArgs.Length == 1)
                                {
                                    var user = _userRepository.GetUser(parsedArgs[0]);
                                    if (user != null)
                                    {
                                        var ignoreItem = this.CommandResult.CurrentUser.Ignores
                                                         .SingleOrDefault(x => x.IgnoredUser.Equals(user.Username));

                                        if ((bool)ignore)
                                        {
                                            if (ignoreItem == null)
                                            {
                                                _userRepository.IgnoreUser(this.CommandResult.CurrentUser.Username, user.Username);
                                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                                this.CommandResult.WriteLine("'{0}' successfully ignored.", user.Username);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You have already ignored '{0}'.", user.Username);
                                            }
                                        }
                                        else if (!(bool)ignore)
                                        {
                                            if (ignoreItem != null)
                                            {
                                                _userRepository.UnignoreUser(this.CommandResult.CurrentUser.Username, user.Username);
                                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                                this.CommandResult.WriteLine("'{0}' successfully unignored.", user.Username);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You have not ignored any users with the username '{0}'.", user.Username);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no user with the username '{0}'.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must specify a username.");
                                }
                            }
                            if (setRole != null)
                            {
                            }
                            if (removeRole != null)
                            {
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #16
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            bool matchFound = false;

            if (args != null)
            {
                try
                {
                    var extra = options.Parse(args);
                    matchFound = args.Length != extra.Count;
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }

            if (!matchFound)
            {
                var registrationStatus = _variableRepository.GetVariable("Registration");
                if (registrationStatus.Value.Equals("Open", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (args.IsNullOrEmpty())
                    {
                        this.CommandResult.WriteLine("Enter your desired username.");
                        this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, args, "Username");
                    }
                    else if (args.Length == 1)
                    {
                        if (args[0].Length > 3)
                        {
                            if (!_userRepository.CheckUserExists(args[0]))
                            {
                                this.CommandResult.WriteLine("Enter your desired password.");
                                this.CommandResult.PasswordField = true;
                                this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, args, "Password");
                            }
                            else
                            {
                                this.CommandResult.WriteLine("Username already exists.");
                                this.CommandResult.WriteLine("Enter a different username.");
                                this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine("Username must be at least four characters long.");
                            this.CommandResult.WriteLine("Enter a different username.");
                            this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                        }
                    }
                    else if (args.Length == 2)
                    {
                        if (args[0].Length > 3)
                        {
                            if (!_userRepository.CheckUserExists(args[0]))
                            {
                                this.CommandResult.WriteLine("Re-enter your desired password.");
                                this.CommandResult.PasswordField = true;
                                this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, args, "Confirm Password");
                            }
                            else
                            {
                                this.CommandResult.WriteLine("Username already exists.");
                                this.CommandResult.WriteLine("Enter your desired username.");
                                this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine("Username must be at least four characters long.");
                            this.CommandResult.WriteLine("Enter a different username.");
                            this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                        }
                    }
                    else if (args.Length == 3)
                    {
                        if (args[0].Length > 3)
                        {
                            var user = this._userRepository.GetUser(args[0]);
                            if (user == null)
                            {
                                if (args[1] == args[2])
                                {
                                    user = new User
                                    {
                                        Username  = args[0],
                                        Password  = args[1],
                                        JoinDate  = DateTime.UtcNow,
                                        LastLogin = DateTime.UtcNow,
                                        TimeZone  = "UTC",
                                        Sound     = true
                                    };
                                    _userRepository.AddRoleToUser(user, "User");
                                    _userRepository.AddUser(user);

                                    this.CommandResult.CurrentUser = user;
                                    this.CommandResult.WriteLine("Thank you for registering.");
                                    this.CommandResult.WriteLine();
                                    var STATS = this.AvailableCommands.SingleOrDefault(x => x.Name.Is("STATS"));
                                    STATS.Invoke(new string[] { "-users" });
                                    this.CommandResult.WriteLine();
                                    this.CommandResult.WriteLine("You are now logged in as {0}.", this.CommandResult.CurrentUser.Username);
                                    this.CommandResult.CommandContext.Deactivate();
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("Passwords did not match.");
                                    this.CommandResult.WriteLine("Enter your desired password.");
                                    this.CommandResult.PasswordField = true;
                                    this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, new string[] { args[0] }, "Password");
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("Username already exists.");
                                this.CommandResult.WriteLine("Enter your desired username.");
                                this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine("Username must be at least four characters long.");
                            this.CommandResult.WriteLine("Enter a different username.");
                            this.CommandResult.CommandContext.Set(ContextStatus.Forced, this.Name, null, "Username");
                        }
                    }
                }
                else
                {
                    this.CommandResult.WriteLine("Registration is currently closed.");
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Display help information for all available commands, or invoke the help argument for a specifically supplied command.
        /// </summary>
        /// <param name="commands">The list of available commands.</param>
        /// <param name="args">Any arguments passed in.</param>
        /// <returns>A CommandResult option containing properties relevant to how data should be processed by the UI.</returns>
        private CommandResult DisplayHelp(IEnumerable <ICommand> commands, string[] args, CommandResult commandResult)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    commandResult,
                    "HELP",
                    "[Option]",
                    "Displays help information.",
                    options
                    );
            }
                );
            try
            {
                if (args != null)
                {
                    var parsedArgs = options.Parse(args);
                    if (parsedArgs.Count == args.Length)
                    {
                        var commandName = parsedArgs.First();
                        var command     = commands.SingleOrDefault(x => x.Name.Is(commandName));
                        if (command != null)
                        {
                            command.Invoke(new string[] { "-help" });
                        }
                        else
                        {
                            commandResult.WriteLine("'{0}' is not a recognized command.", commandName);
                        }
                    }
                }
                else
                {
                    commandResult.WriteLine("The following commands are available:");
                    commandResult.WriteLine();
                    foreach (ICommand command in commands.OrderBy(x => x.Name))
                    {
                        if (command.ShowHelp)
                        {
                            commandResult.WriteLine(DisplayMode.DontType, "{0}{1}", command.Name.PadRight(15), command.Description);
                        }
                    }
                    commandResult.WriteLine();
                    commandResult.WriteLine("Type \"COMMAND -?\" for details on individual commands.");
                    if (_currentUser != null)
                    {
                        commandResult.WriteLine();
                        commandResult.WriteLine(DisplayMode.Dim | DisplayMode.DontType, new string('-', AppSettings.DividerLength));
                        commandResult.WriteLine();
                        var aliases = _aliasRepository.GetAliases(_currentUser.Username);
                        if (aliases.Count() > 0)
                        {
                            commandResult.WriteLine("You have the following aliases defined:");
                            commandResult.WriteLine();
                            foreach (var alias in aliases)
                            {
                                commandResult.WriteLine(DisplayMode.DontType, "{0}'{1}'", alias.Shortcut.ToUpper().PadRight(15, ' '), alias.Command);
                            }
                        }
                        else
                        {
                            commandResult.WriteLine("You have no aliases defined.");
                        }
                    }
                }
            }
            catch (OptionException ex)
            {
                commandResult.WriteLine(ex.Message);
            }

            return(commandResult);
        }
Пример #18
0
        public void Invoke(string[] args)
        {
            bool showHelp       = false;
            bool?mute           = null;
            bool changePassword = false;
            bool setTimeZone    = false;
            bool?timeStamps     = null;
            bool?autoFollow     = null;
            bool?replyNotify    = null;
            bool?messageNotify  = null;
            bool?registration   = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "m|mute",
                "Mute/unmute the U413 typing sound.",
                x => mute = x != null
                );
            options.Add(
                "changePassword",
                "Change your current password.",
                x => changePassword = x != null
                );
            options.Add(
                "setTimeZone",
                "Set your current time zone.",
                x => setTimeZone = x != null
                );
            options.Add(
                "timeStamps",
                "Turn timestamps on/off.",
                x => timeStamps = x != null
                );
            options.Add(
                "autoFollow",
                "Auto-follow topics you create or reply to.",
                x => autoFollow = x != null
                );
            options.Add(
                "replyNotify",
                "Display notifications about replies to your followed topics.",
                x => replyNotify = x != null
                );
            options.Add(
                "msgNotify",
                "Display notifications for unread messages in your inbox.",
                x => messageNotify = x != null
                );
            if (this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "reg|registration",
                    "Open or close registration.",
                    x => registration = x != null
                    );
            }

            if (args == null)
            {
                this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (changePassword)
                        {
                            if (this.CommandResult.CommandContext.PromptData == null)
                            {
                                this.CommandResult.WriteLine("Type your new password.");
                                this.CommandResult.PasswordField = true;
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "NEW PASSWORD");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                            {
                                this.CommandResult.WriteLine("Confirm your new password.");
                                this.CommandResult.PasswordField = true;
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "CONFIRM PASSWORD");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                            {
                                string password        = this.CommandResult.CommandContext.PromptData[0];
                                string confirmPassword = this.CommandResult.CommandContext.PromptData[1];
                                if (password == confirmPassword)
                                {
                                    this.CommandResult.CurrentUser.Password = password;
                                    _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                    this.CommandResult.WriteLine("Password changed successfully.");
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("Passwords did not match.");
                                }
                                this.CommandResult.CommandContext.Restore();
                            }
                        }
                        else if (setTimeZone)
                        {
                            var timeZones = TimeZoneInfo.GetSystemTimeZones();
                            if (this.CommandResult.CommandContext.PromptData == null)
                            {
                                for (int index = 0; index < timeZones.Count; index++)
                                {
                                    var timeZone = timeZones[index];
                                    this.CommandResult.WriteLine(DisplayMode.DontType, "{{{0}}} {1}", index, timeZone.DisplayName);
                                }
                                this.CommandResult.WriteLine();
                                this.CommandResult.WriteLine("Enter time zone ID.");
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "CHANGE TIME ZONE");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                            {
                                string promptData = this.CommandResult.CommandContext.PromptData[0];
                                if (promptData.IsInt())
                                {
                                    int timeZoneId = promptData.ToInt();
                                    if (timeZoneId >= 0 && timeZoneId < timeZones.Count)
                                    {
                                        var timeZone = timeZones[timeZoneId];
                                        this.CommandResult.CurrentUser.TimeZone = timeZone.Id;
                                        _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                        this.CommandResult.WriteLine("'{0}' successfully set as your current time zone.", timeZone.Id);
                                        this.CommandResult.CommandContext.Restore();
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' does not match any available time zone ID.", timeZoneId);
                                        this.CommandResult.CommandContext.Restore();
                                        this.CommandResult.WriteLine("Enter time zone ID.");
                                        this.CommandResult.CommandContext.SetPrompt(this.Name, args, "CHANGE TIME ZONE");
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid time zone ID.", promptData);
                                    this.CommandResult.CommandContext.Restore();
                                    this.CommandResult.WriteLine("Enter time zone ID.");
                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, "CHANGE TIME ZONE");
                                }
                            }
                        }
                        else
                        {
                            if (mute != null)
                            {
                                this.CommandResult.CurrentUser.Sound = !(bool)mute;
                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                this.CommandResult.WriteLine("Sound successfully {0}.", (bool)mute ? "muted" : "unmuted");
                            }
                            if (timeStamps != null)
                            {
                                this.CommandResult.CurrentUser.ShowTimestamps = (bool)timeStamps;
                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                this.CommandResult.WriteLine("Timestamps were successfully {0}.", (bool)timeStamps ? "enabled" : "disabled");
                            }
                            if (autoFollow != null)
                            {
                                this.CommandResult.CurrentUser.AutoFollow = (bool)autoFollow;
                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                this.CommandResult.WriteLine("Auto-follow {0}.", (bool)autoFollow ? "activated" : "deactivated");
                            }
                            if (replyNotify != null)
                            {
                                this.CommandResult.CurrentUser.NotifyReplies = (bool)replyNotify;
                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                this.CommandResult.WriteLine("Reply notifications were successfully turned {0}.", (bool)replyNotify ? "on" : "off");
                            }
                            if (messageNotify != null)
                            {
                                this.CommandResult.CurrentUser.NotifyMessages = (bool)messageNotify;
                                _userRepository.UpdateUser(this.CommandResult.CurrentUser);
                                this.CommandResult.WriteLine("Message notifications were successfully turned {0}.", (bool)messageNotify ? "on" : "off");
                            }
                            if (registration != null)
                            {
                                var registrationStatus = _variableRepository.GetVariable("Registration");
                                if ((bool)registration)
                                {
                                    registrationStatus.Value = "Open";
                                }
                                else if (!(bool)registration)
                                {
                                    registrationStatus.Value = "Closed";
                                }
                                _variableRepository.ModifyVariable(registrationStatus);
                                this.CommandResult.WriteLine("U413 registration was successfully {0}.", (bool)registration ? "opened" : "closed");
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #19
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            if (args == null)
            {
                this.CommandResult.ScrollToBottom = false;
                this.CommandResult.CommandContext.Deactivate();
                this.CommandResult.ClearScreen = true;
                this.CommandResult.WriteLine(DisplayMode.Inverted | DisplayMode.DontType, "Available Discussion Boards");
                var boards = _boardRepository.GetBoards(this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator);
                foreach (var board in boards)
                {
                    this.CommandResult.WriteLine();
                    var displayMode = DisplayMode.DontType;
                    if (board.ModsOnly || board.Hidden)
                    {
                        displayMode |= DisplayMode.Dim;
                    }
                    long topicCount = board.BoardID == 0
                        ? _topicRepository.AllTopicsCount()
                        : board.TopicCount(this.CommandResult.CurrentUser.IsModerator);

                    this.CommandResult.WriteLine(displayMode, "{{{0}}} {1}{2}{3}{4}{5} | {6} topics",
                                                 board.BoardID == 7 ? board.BoardID.ToString().PadLeft(3, '0') : board.BoardID.ToString(),
                                                 board.Hidden ? "[HIDDEN] " : string.Empty,
                                                 board.ModsOnly ? "[MODSONLY] " : string.Empty,
                                                 board.Locked ? "[LOCKED] " : string.Empty,
                                                 board.Anonymous ? "[ANON] " : string.Empty,
                                                 board.Name,
                                                 topicCount);

                    if (!board.Description.IsNullOrEmpty())
                    {
                        this.CommandResult.WriteLine(displayMode, "{0}", board.Description);
                    }
                }
                if (boards.Count() == 0)
                {
                    this.CommandResult.WriteLine("There are no discussion boards.");
                }
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #20
0
        public void Invoke(string[] args)
        {
            bool showHelp  = false;
            bool newTopic  = false;
            bool modTopic  = false;
            bool refresh   = false;
            bool?lockBoard = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "R|refresh",
                "Refresh the current board.",
                x => refresh = x != null
                );
            options.Add(
                "nt|newTopic",
                "Create new topic on the specified board.",
                x => newTopic = x != null
                );
            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "mt|modTopic",
                    "Create a topic that only moderators can see.",
                    x =>
                {
                    newTopic = x != null;
                    modTopic = x != null;
                }
                    );
            }
            if (this.CommandResult.CurrentUser.IsAdministrator)
            {
                options.Add(
                    "l|lock",
                    "Lock the board to prevent creation of topics.",
                    x => lockBoard = x != null
                    );
            }

            if (args == null)
            {
                this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            if (parsedArgs[0].IsShort())
                            {
                                var boardId = parsedArgs[0].ToShort();
                                var board   = _boardRepository.GetBoard(boardId);
                                var page    = 1;
                                if (board != null)
                                {
                                    if (board.ModsOnly)
                                    {
                                        if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            WriteTopics(boardId, page);
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("You do not have permission to access this board.");
                                        }
                                    }
                                    else
                                    {
                                        WriteTopics(boardId, page);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                            }
                        }
                        else if (parsedArgs.Length == 2)
                        {
                            if (parsedArgs[0].IsShort())
                            {
                                var boardId = parsedArgs[0].ToShort();
                                if (parsedArgs[1].IsInt())
                                {
                                    var page  = parsedArgs[1].ToInt();
                                    var board = _boardRepository.GetBoard(boardId);
                                    if (board != null)
                                    {
                                        if (board.ModsOnly)
                                        {
                                            if (this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                WriteTopics(boardId, page);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You do not have permission to access this board.");
                                            }
                                        }
                                        else
                                        {
                                            WriteTopics(boardId, page);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                                    }
                                }
                                else if (PagingUtility.Shortcuts.Any(x => parsedArgs[1].Is(x)))
                                {
                                    var page = PagingUtility.TranslateShortcut(parsedArgs[1], this.CommandResult.CommandContext.CurrentPage);
                                    WriteTopics(boardId, page);
                                    if (parsedArgs[1].Is("last") || parsedArgs[1].Is("prev"))
                                    {
                                        this.CommandResult.ScrollToBottom = false;
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid page number.", parsedArgs[1]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (newTopic)
                        {
                            if (parsedArgs.Length >= 1)
                            {
                                if (parsedArgs[0].IsShort())
                                {
                                    var boardId = parsedArgs[0].ToShort();
                                    var board   = _boardRepository.GetBoard(boardId);
                                    if (board != null)
                                    {
                                        if (!board.Locked || this.CommandResult.CurrentUser.IsAdministrator)
                                        {
                                            if (!board.ModsOnly || this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator)
                                            {
                                                if (this.CommandResult.CommandContext.PromptData == null)
                                                {
                                                    this.CommandResult.WriteLine("Create a title for your topic.");
                                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} NEW TOPIC Title", boardId));
                                                }
                                                else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                                {
                                                    this.CommandResult.WriteLine("Create the body for your topic.");
                                                    this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} NEW TOPIC Body", boardId));
                                                }
                                                else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                                                {
                                                    Topic topic = new Topic
                                                    {
                                                        BoardID = boardId,
                                                        Title   = this.CommandResult.CommandContext.PromptData[0],
                                                        Body    = BBCodeUtility.SimplifyComplexTags(
                                                            this.CommandResult.CommandContext.PromptData[1],
                                                            _replyRepository,
                                                            this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator
                                                            ),
                                                        Username   = this.CommandResult.CurrentUser.Username,
                                                        PostedDate = DateTime.UtcNow,
                                                        LastEdit   = DateTime.UtcNow,
                                                        ModsOnly   = modTopic && !board.ModsOnly
                                                    };
                                                    _topicRepository.AddTopic(topic);
                                                    this.CommandResult.CommandContext.Restore();
                                                    var TOPIC = this.AvailableCommands.SingleOrDefault(x => x.Name.Is("TOPIC"));
                                                    TOPIC.Invoke(new string[] { topic.TopicID.ToString() });
                                                    this.CommandResult.WriteLine("New topic succesfully posted.");
                                                }
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("Board '{0}' is for moderators only.", boardId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Board '{0}' is locked. You cannot create topics on this board.", boardId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no board with ID '{0}'.", boardId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a board ID.");
                            }
                        }
                        else
                        {
                            if (lockBoard != null)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsShort())
                                    {
                                        var boardId = parsedArgs[0].ToShort();
                                        var board   = _boardRepository.GetBoard(boardId);
                                        if (board != null)
                                        {
                                            board.Locked = (bool)lockBoard;
                                            _boardRepository.UpdateBoard(board);
                                            string status = (bool)lockBoard ? "locked" : "unlocked";
                                            this.CommandResult.WriteLine("Board '{0}' was successfully {1}.", boardId, status);
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("There is no board with ID '{0}'.", boardId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a board ID.");
                                }
                            }
                            if (refresh)
                            {
                                if (parsedArgs.Length > 0)
                                {
                                    if (parsedArgs[0].IsShort())
                                    {
                                        var boardId = parsedArgs[0].ToShort();
                                        WriteTopics(boardId, this.CommandResult.CommandContext.CurrentPage);
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("You must supply a board ID.");
                                }
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #21
0
        public void Invoke(string[] args)
        {
            bool showHelp    = false;
            bool delete      = false;
            bool?lockMessage = null;
            bool reply       = false;
            bool newMessage  = false;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "r|reply",
                "Reply to the specified message.",
                x => reply = x != null
                );
            options.Add(
                "d|delete",
                "Deletes the specified message.",
                x => delete = x != null
                );
            options.Add(
                "l|lock",
                "Locks the message to prevent accidental deltion.",
                x => lockMessage = x != null
                );
            options.Add(
                "nm|newMessage",
                "Send a new message to a fellow PIrate.",
                x => newMessage = x != null
                );

            if (args == null)
            {
                this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        if (parsedArgs.Length == 1)
                        {
                            if (parsedArgs[0].IsLong())
                            {
                                var messageId = parsedArgs[0].ToLong();
                                WriteMessage(messageId);
                            }
                            else
                            {
                                this.CommandResult.WriteLine("'{0}' is not a valid board ID.", parsedArgs[0]);
                            }
                        }
                        else
                        {
                            this.CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                        }
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(
                                this.CommandResult,
                                this.Name,
                                this.Parameters,
                                this.Description,
                                options
                                );
                        }
                        else if (reply)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var messageId = parsedArgs[0].ToLong();
                                    var message   = _messageRepository.GetMessage(messageId);
                                    if (message != null)
                                    {
                                        if (message.Recipient.Is(this.CommandResult.CurrentUser.Username))
                                        {
                                            if (this.CommandResult.CommandContext.PromptData == null)
                                            {
                                                this.CommandResult.WriteLine("Write the body of your message.");
                                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, string.Format("{0} REPLY Body", messageId));
                                            }
                                            else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                                            {
                                                _messageRepository.AddMessage(new Message
                                                {
                                                    Body             = this.CommandResult.CommandContext.PromptData[0],
                                                    RecipientLocked  = false,
                                                    SenderLocked     = false,
                                                    MessageRead      = false,
                                                    Recipient        = message.Sender,
                                                    Sender           = this.CommandResult.CurrentUser.Username,
                                                    RecipientDeleted = false,
                                                    SenderDeleted    = false,
                                                    Subject          = string.Format("Re: {0}", message.Subject),
                                                    SentDate         = DateTime.UtcNow
                                                });
                                                this.CommandResult.WriteLine("Reply sent succesfully.");
                                                this.CommandResult.CommandContext.Restore();
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Message '{0}' was not sent to you.", messageId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no message with ID '{0}'.", messageId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid message ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a message ID.");
                            }
                        }
                        else if (delete)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var messageId = parsedArgs[0].ToLong();
                                    var message   = _messageRepository.GetMessage(messageId);
                                    if (message != null)
                                    {
                                        if (message.Recipient.Is(this.CommandResult.CurrentUser.Username))
                                        {
                                            if (!message.RecipientLocked)
                                            {
                                                message.RecipientDeleted = true;
                                                _messageRepository.UpdateMessage(message);
                                                this.CommandResult.WriteLine("Message '{0}' deleted successfully.", messageId);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You have locked message '{0}' and cannot delete it.", messageId);
                                            }
                                        }
                                        else if (message.Sender.Is(this.CommandResult.CurrentUser.Username))
                                        {
                                            if (!message.SenderLocked)
                                            {
                                                message.SenderDeleted = true;
                                                _messageRepository.UpdateMessage(message);
                                                this.CommandResult.WriteLine("Message '{0}' deleted successfully.", messageId);
                                            }
                                            else
                                            {
                                                this.CommandResult.WriteLine("You have locked message '{0}' and cannot delete it.", messageId);
                                            }
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Message '{0}' does not belong to you.", messageId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no message with ID '{0}'.", messageId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid message ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a message ID.");
                            }
                        }
                        else if (newMessage)
                        {
                            if (this.CommandResult.CommandContext.PromptData == null)
                            {
                                this.CommandResult.WriteLine("Type the name of the recipient.");
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "USERNAME");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 1)
                            {
                                this.CommandResult.WriteLine("Type the subject of your message.");
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "SUBJECT");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 2)
                            {
                                this.CommandResult.WriteLine("Type the body of your message.");
                                this.CommandResult.CommandContext.SetPrompt(this.Name, args, "BODY");
                            }
                            else if (this.CommandResult.CommandContext.PromptData.Length == 3)
                            {
                                _messageRepository.AddMessage(new Message
                                {
                                    Sender    = this.CommandResult.CurrentUser.Username,
                                    Recipient = this.CommandResult.CommandContext.PromptData[0],
                                    Subject   = this.CommandResult.CommandContext.PromptData[1],
                                    Body      = this.CommandResult.CommandContext.PromptData[2],
                                    SentDate  = DateTime.UtcNow
                                });
                                this.CommandResult.WriteLine("Message sent succesfully.");
                                this.CommandResult.CommandContext.Restore();
                            }
                        }
                        else
                        if (lockMessage != null)
                        {
                            if (parsedArgs.Length > 0)
                            {
                                if (parsedArgs[0].IsLong())
                                {
                                    var messageId = parsedArgs[0].ToLong();
                                    var message   = _messageRepository.GetMessage(messageId);
                                    if (message != null)
                                    {
                                        if (message.Recipient.Is(this.CommandResult.CurrentUser.Username))
                                        {
                                            message.RecipientLocked = (bool)lockMessage;
                                            _messageRepository.UpdateMessage(message);
                                            this.CommandResult.WriteLine("Message '{0}' {1} successfully.", messageId, (bool)lockMessage ? "locked" : "unlocked");
                                        }
                                        else if (message.Sender.Is(this.CommandResult.CurrentUser.Username))
                                        {
                                            message.SenderLocked = (bool)lockMessage;
                                            _messageRepository.UpdateMessage(message);
                                            this.CommandResult.WriteLine("Message '{0}' {1} successfully.", messageId, (bool)lockMessage ? "locked" : "unlocked");
                                        }
                                        else
                                        {
                                            this.CommandResult.WriteLine("Message '{0}' does not belong to you.", messageId);
                                        }
                                    }
                                    else
                                    {
                                        this.CommandResult.WriteLine("There is no message with ID '{0}'.", messageId);
                                    }
                                }
                                else
                                {
                                    this.CommandResult.WriteLine("'{0}' is not a valid message ID.", parsedArgs[0]);
                                }
                            }
                            else
                            {
                                this.CommandResult.WriteLine("You must supply a message ID.");
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #22
0
        public void Invoke(string[] args)
        {
            bool showHelp = false;
            bool users    = false;
            bool mods     = false;
            bool forum    = false;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "users",
                "Show statistics about members.",
                x => users = x != null
                );
            options.Add(
                "modsquad",
                "List all moderators.",
                x => mods = x != null
                );
            options.Add(
                "forum",
                "Display forum statistics.",
                x => forum = x != null
                );

            if (args == null)
            {
                CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(this, options);
                        }
                        else
                        {
                            if (users)
                            {
                                var userStats     = _dataBucket.UserRepository.GetUserStatistics();
                                var loggedInUsers = _dataBucket.UserRepository.GetLoggedInUsers();

                                var displayMode = DisplayMode.DontType;
                                CommandResult.WriteLine(displayMode, "There are {0} users registered.", userStats.TotalRegisteredUsers);
                                CommandResult.WriteLine(displayMode, "{0} users are currently banned for various bad manners.", userStats.TotalBannedUsers);
                                CommandResult.WriteLine();
                                CommandResult.WriteLine(displayMode, "{0} users have registered within the last 24 hours.", userStats.NewUsersInTheLast24Hours);
                                CommandResult.WriteLine(displayMode, "{0} users have registered within the last week.", userStats.NewUsersInTheLastWeek);
                                CommandResult.WriteLine(displayMode, "{0} users have registered within the last month.", userStats.NewUsersInTheLastMonth);
                                CommandResult.WriteLine(displayMode, "{0} users have registered within the last year.", userStats.NewUsersInTheLastYear);
                                CommandResult.WriteLine();
                                CommandResult.WriteLine(displayMode, "{0} users have logged in within the last 24 hours.", userStats.LoggedInWithinTheLast24Hours);
                                CommandResult.WriteLine(displayMode, "{0} users have logged in within the last week.", userStats.LoggedInWithinTheLastWeek);
                                CommandResult.WriteLine(displayMode, "{0} users have logged in within the last month.", userStats.LoggedInWithinTheLastMonth);
                                CommandResult.WriteLine(displayMode, "{0} users have logged in within the last year.", userStats.LoggedInWithinTheLastYear);
                                CommandResult.WriteLine();
                                CommandResult.WriteLine(displayMode | DisplayMode.Dim, new string('-', AppSettings.DividerLength));
                                CommandResult.WriteLine();
                                CommandResult.WriteLine(displayMode, "There are currently {0} user(s) online.", loggedInUsers.Count());
                                CommandResult.WriteLine();
                                foreach (var user in loggedInUsers)
                                {
                                    CommandResult.WriteLine(displayMode, user.Username);
                                }
                            }
                            if (mods)
                            {
                                var staff       = _dataBucket.UserRepository.GetModeratorsAndAdministrators();
                                var displayMode = DisplayMode.DontType;
                                CommandResult.WriteLine(displayMode, "There are {0} moderators.", staff.Count());
                                CommandResult.WriteLine();
                                foreach (var user in staff)
                                {
                                    var tenMinutesAgo = DateTime.UtcNow.AddMinutes(-10);
                                    var isOnline      = user.LastLogin > tenMinutesAgo;
                                    CommandResult.WriteLine(
                                        displayMode,
                                        "{0}{1}{2}",
                                        user.Username,
                                        user.IsAdministrator ? " (admin)" : null,
                                        isOnline ? " (online)" : null
                                        );
                                }
                            }
                            if (forum)
                            {
                                var forumStats = _dataBucket.TopicRepository.GetForumStats();
                                int numReplies = _dataBucket.TopicRepository.GetTopic(forumStats.MostPopularTopic).Replies.Count();

                                var displayMode = DisplayMode.DontType;
                                CommandResult.WriteLine(displayMode, "There are {0} total topics.", forumStats.TotalTopics);
                                CommandResult.WriteLine(displayMode, "Topic {0} is the most popular topic with {1} replies.", forumStats.MostPopularTopic, numReplies);
                                CommandResult.WriteLine(displayMode, "{0} topics have been created within the last 24 hours.", forumStats.TopicsInTheLast24Hours);
                                CommandResult.WriteLine(displayMode, "{0} topics have been created within the last week.", forumStats.TopicsInTheLastWeek);
                                CommandResult.WriteLine(displayMode, "{0} topics have been created within the last month.", forumStats.TopicsInTheLastMonth);
                                CommandResult.WriteLine(displayMode, "{0} topics have been created within the last year.", forumStats.TopicsInTheLastYear);
                                CommandResult.WriteLine();
                                CommandResult.WriteLine(displayMode, "There are {0} total posts.", forumStats.TotalPosts);
                                CommandResult.WriteLine(displayMode, "{0} posts have been made within the last 24 hours.", forumStats.PostsInTheLast24Hours);
                                CommandResult.WriteLine(displayMode, "{0} posts have been made within the last week.", forumStats.PostsInTheLastWeek);
                                CommandResult.WriteLine(displayMode, "{0} posts have been made within the last month.", forumStats.PostsInTheLastMonth);
                                CommandResult.WriteLine(displayMode, "{0} posts have been made within the last year.", forumStats.PostsInTheLastYear);
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #23
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            List <string> parsedArgs = null;

            if (args != null)
            {
                try
                {
                    parsedArgs = options.Parse(args);
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }

            var registrationStatus = _dataBucket.VariableRepository.GetVariable("Registration");

            if (registrationStatus.Equals("Open", StringComparison.InvariantCultureIgnoreCase) || CommandResult.CommandContext.PromptData != null)
            {
                CommandResult.CommandContext.Prompt = false;
                InviteCode inviteCode = null;
                if (CommandResult.CommandContext.PromptData != null)
                {
                    inviteCode = _dataBucket.InviteCodeRepository.GetInviteCode(CommandResult.CommandContext.PromptData[0]);
                }

                if (CommandResult.CommandContext.PromptData == null || inviteCode != null)
                {
                    if (inviteCode != null)
                    {
                        if (parsedArgs == null)
                        {
                            parsedArgs = new List <string> {
                                inviteCode.Username
                            }
                        }
                        ;
                        else
                        {
                            parsedArgs.Insert(0, inviteCode.Username);
                        }
                    }
                    if ((parsedArgs == null || parsedArgs.Count == 0))
                    {
                        CommandResult.WriteLine("Enter your desired username. (no spaces. sorry.)");
                        CommandResult.SetContext(ContextStatus.Forced, Name, args, "Username");
                    }
                    else if (parsedArgs.Count == 1)
                    {
                        if (parsedArgs[0].Length >= 3 && parsedArgs[0].Length <= 30)
                        {
                            if (!_dataBucket.UserRepository.CheckUserExists(parsedArgs[0]))
                            {
                                CommandResult.WriteLine("Enter your desired password.");
                                CommandResult.PasswordField = true;
                                CommandResult.SetContext(ContextStatus.Forced, Name, args, "Password");
                            }
                            else
                            {
                                CommandResult.WriteLine("Username already exists.");
                                CommandResult.WriteLine("Enter a different username.");
                                CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                            }
                        }
                        else
                        {
                            CommandResult.WriteLine("Username must be between 3 and 15 characters.");
                            CommandResult.WriteLine("Enter a different username.");
                            CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                        }
                    }
                    else if (parsedArgs.Count == 2)
                    {
                        if (parsedArgs[0].Length >= 3 && parsedArgs[0].Length <= 15)
                        {
                            if (!_dataBucket.UserRepository.CheckUserExists(parsedArgs[0]))
                            {
                                CommandResult.WriteLine("Re-enter your desired password.");
                                CommandResult.PasswordField = true;
                                CommandResult.SetContext(ContextStatus.Forced, Name, args, "Confirm Password");
                            }
                            else
                            {
                                CommandResult.WriteLine("Username already exists.");
                                CommandResult.WriteLine("Enter your desired username.");
                                CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                            }
                        }
                        else
                        {
                            CommandResult.WriteLine("Username must be between 3 and 15 characters.");
                            CommandResult.WriteLine("Enter a different username.");
                            CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                        }
                    }
                    else if (parsedArgs.Count == 3)
                    {
                        if (parsedArgs[0].Length >= 3 && parsedArgs[0].Length <= 15)
                        {
                            var user = _dataBucket.UserRepository.GetUser(parsedArgs[0]);
                            if (user == null)
                            {
                                if (parsedArgs[1] == parsedArgs[2])
                                {
                                    user = new User
                                    {
                                        Username  = parsedArgs[0],
                                        Password  = parsedArgs[1],
                                        JoinDate  = DateTime.UtcNow,
                                        LastLogin = DateTime.UtcNow,
                                        TimeZone  = "UTC",
                                        Sound     = true,
                                    };
                                    var role = _dataBucket.UserRepository.GetRole("User");
                                    user.Roles = new List <Role> {
                                        role
                                    };

                                    if (inviteCode != null)
                                    {
                                        _dataBucket.InviteCodeRepository.DeleteInviteCode(inviteCode);
                                    }

                                    _dataBucket.UserRepository.AddUser(user);
                                    _dataBucket.SaveChanges();


                                    var defaultAliases = new List <Alias>
                                    {
                                        new Alias
                                        {
                                            Username = user.Username,
                                            Shortcut = "lb",
                                            Command  = "BOARDS"
                                        },
                                        new Alias
                                        {
                                            Username = user.Username,
                                            Shortcut = "b",
                                            Command  = "BOARD"
                                        },
                                        new Alias
                                        {
                                            Username = user.Username,
                                            Shortcut = "t",
                                            Command  = "TOPIC"
                                        },
                                        new Alias
                                        {
                                            Username = user.Username,
                                            Shortcut = "lm",
                                            Command  = "MESSAGES"
                                        },
                                        new Alias
                                        {
                                            Username = user.Username,
                                            Shortcut = "m",
                                            Command  = "MESSAGE"
                                        }
                                    };

                                    defaultAliases.ForEach(x => _dataBucket.AliasRepository.AddAlias(x));
                                    _dataBucket.SaveChanges();

                                    CommandResult.CurrentUser = user;
                                    CommandResult.WriteLine("Thank you for registering.");
                                    //CommandResult.WriteLine();
                                    //var STATS = AvailableCommands.SingleOrDefault(x => x.Name.Is("STATS"));
                                    //STATS.Invoke(new string[] { "-users" });
                                    CommandResult.WriteLine();
                                    CommandResult.WriteLine("You are now logged in as {0}.", CommandResult.CurrentUser.Username);
                                    CommandResult.DeactivateContext();
                                }
                                else
                                {
                                    CommandResult.WriteLine("Passwords did not match.");
                                    CommandResult.WriteLine("Enter your desired password.");
                                    CommandResult.PasswordField = true;
                                    CommandResult.SetContext(ContextStatus.Forced, Name, new string[] { parsedArgs[0] }, "Password");
                                }
                            }
                            else
                            {
                                CommandResult.WriteLine("Username already exists.");
                                CommandResult.WriteLine("Enter your desired username.");
                                CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                            }
                        }
                        else
                        {
                            CommandResult.WriteLine("Username must be between 3 and 15 characters.");
                            CommandResult.WriteLine("Enter a different username.");
                            CommandResult.SetContext(ContextStatus.Forced, Name, null, "Username");
                        }
                    }
                }
                else
                {
                    CommandResult.WriteLine("You did not supply a valid invite code.");
                    CommandResult.DeactivateContext();
                }
            }
            else if (registrationStatus.Equals("Invite-Only", StringComparison.InvariantCultureIgnoreCase))
            {
                CommandResult.WriteLine("Enter your invite code.");
                CommandResult.SetPrompt(Name, args, "Invite Code");
            }
            else if (registrationStatus.Equals("Closed", StringComparison.InvariantCultureIgnoreCase))
            {
                CommandResult.WriteLine("Registration is currently closed.");
            }
        }
Пример #24
0
        public void Invoke(string[] args)
        {
            bool   showHelp    = false;
            string newAlias    = null;
            string deleteAlias = null;

            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => showHelp = x != null
                );
            options.Add(
                "n|new=",
                "Create a new {alias}.",
                x => newAlias = x
                );
            options.Add(
                "d|delete=",
                "Delete an existing {alias}.",
                x => deleteAlias = x
                );

            if (args == null)
            {
                CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
            }
            else
            {
                try
                {
                    var parsedArgs = options.Parse(args).ToArray();

                    if (parsedArgs.Length == args.Length)
                    {
                        CommandResult.WriteLine(DisplayTemplates.InvalidArguments);
                    }
                    else
                    {
                        if (showHelp)
                        {
                            HelpUtility.WriteHelpInformation(this, options);
                        }
                        else if (newAlias != null)
                        {
                            if (!newAlias.Is("HELP") && !AvailableCommands.Any(x => x.Name.Is(newAlias)))
                            {
                                var alias = _dataBucket.AliasRepository.GetAlias(CommandResult.CurrentUser.Username, newAlias);
                                if (alias == null)
                                {
                                    if (CommandResult.CommandContext.PromptData == null)
                                    {
                                        CommandResult.WriteLine("Type the value that should be sent to the terminal when you use your new alias.");
                                        CommandResult.SetPrompt(Name, args, string.Format("{0} VALUE", newAlias.ToUpper()));
                                    }
                                    else if (CommandResult.CommandContext.PromptData.Length == 1)
                                    {
                                        _dataBucket.AliasRepository.AddAlias(new Alias
                                        {
                                            Username = CommandResult.CurrentUser.Username,
                                            Shortcut = newAlias,
                                            Command  = CommandResult.CommandContext.PromptData[0]
                                        });
                                        _dataBucket.SaveChanges();
                                        CommandResult.WriteLine("Alias '{0}' was successfully defined.", newAlias.ToUpper());
                                        CommandResult.RestoreContext();
                                    }
                                }
                                else
                                {
                                    CommandResult.WriteLine("You have already defined an alias named '{0}'.", newAlias.ToUpper());
                                }
                            }
                            else
                            {
                                CommandResult.WriteLine("'{0}' is an existing command. You cannot create aliases with the same name as existing commands.", newAlias.ToUpper());
                            }
                        }
                        else if (deleteAlias != null)
                        {
                            var alias = _dataBucket.AliasRepository.GetAlias(CommandResult.CurrentUser.Username, deleteAlias);
                            if (alias != null)
                            {
                                _dataBucket.AliasRepository.DeleteAlias(alias);
                                _dataBucket.SaveChanges();
                                CommandResult.WriteLine("Alias '{0}' was successfully deleted.", deleteAlias.ToUpper());
                            }
                            else
                            {
                                CommandResult.WriteLine("You have not defined an alias named '{0}'.", deleteAlias.ToUpper());
                            }
                        }
                    }
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.Message);
                }
            }
        }
Пример #25
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x => HelpUtility.WriteHelpInformation(this, options)
                );

            if (args != null)
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    CommandResult.WriteLine(ex.ToString());
                }
            }
            else
            {
                CommandResult.WriteLine(DisplayMode.Inverted, "OMEGA LOCKDOWN ACTIVE");
                CommandResult.WriteLine();
                CommandResult.WriteLine("Welcome agent {0}. I see that you are interested in learning more about the Omega Directive.", CommandResult.CurrentUser.Username);
                CommandResult.WriteLine("We'll begin your briefing from the beginning.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("As an agent of the resistance you already know about exotic matter (XM).");
                CommandResult.WriteLine("What you don't know is that humanity has encountered this matter before the secret French experiments that you've been told about.");
                CommandResult.WriteLine("Exotic matter consists of a group of unknown but powerful particles chemically bonded to form what is known as the Omega Molecule.");
                CommandResult.WriteLine("Strange energetic properties exhibited by Omega resulted in heavy experimentation as scientists believed Omega, if harnessed correctly, could be a virtually unlimited source of energy.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("Unfortunately, Omega proved to be extremely unstable and all attempts to stabalize it were unsuccessful. Not long into the project one of the experimental attempts at stabalization went extremely wrong.");
                CommandResult.WriteLine("In the middle of the experiment several molecules were successfully fused into a stable molecular lattice, but it didn't last long.");
                CommandResult.WriteLine();
                CommandResult.WriteLine(DisplayMode.DontType | DisplayMode.DontWrap | DisplayMode.Parse, "[img]http://omegamolecule.com/content/OmegaLattice.jpg[/img]");
                CommandResult.WriteLine();
                CommandResult.WriteLine("The Omega lattice immediately began to break down causing a chain reaction. The scientists only had a few seconds to enact emergency safety protocols and fill the test chamber with liquid nitrogen, halting the breakdown in mid-cascade.");
                CommandResult.WriteLine("The energy buildup during the last few seconds of the experiment was analyzed vigorously. When the data came back the results were astounding.");
                CommandResult.WriteLine("Just a handful of Omega molecules, if allowed to continue breaking down, would have released an energy equivalent to 1100 times that of an atomic bomb.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("Once the destructive power was revealed it was determined that Omega was too unstable for experimentation and the project was put on permanent hold.");
                CommandResult.WriteLine("The Omega Directive was created to monitor the state of Omega here on Earth and prevent others from experimenting with the molecule.");
                CommandResult.WriteLine("For years nobody else discovered the power of Omega. Several had come close, but never close enough to require intervention, until late last year.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("We have no idea where the first particals of XM began to appear, but it seems the once rare matter is now more abundant on the Earth than we could ever have imagined.");
                CommandResult.WriteLine("XM appears to gather near interesting anomalies known to you as \"portals\". Much to our surprise, these portals appear to be stable structures of Omega Molecules.");
                CommandResult.WriteLine("Needless to say, when we first discovered the properties of these portals we were extremely alarmed and we have since initiated a code blue Omega lockdown as per article 21 subsection D of the Omega Directive.");
                CommandResult.WriteLine("This lockdown forbids us from sharing information about Omega for fear that it could fall into the wrong hands. We must continue to operate in secrecy to protect our race.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("During the lockdown we have continued analyzing these new anomalies to gain a better understanding of the phenomenon. Most members of the Omega Directive have arrived at a consensus that it is highly implausible for these anomalies consisting of stable Omega Molecules to be a natural occurance.");
                CommandResult.WriteLine("Only an intelligence with an extensive understanding of Omega would be able to create so many stable structures. Many have theorized that if enough of these stable anomalies remain within this unkown intelligence's control they could be linked together to form a \"super lattice\". Such a structure would be capable of crossing dimensional barriers that we never imagined existed, let alone that we could cross.");
                CommandResult.WriteLine("As XM particles continue to accumulate around the globe we are becoming increasingly concerned and we must do everything we can to stop it.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("Omega is extremely difficult to erradicate safely. Fortunately for now the stabalization process used on XM particles to form stable Omega structures appears to be practically flawless. Though we are still concerned about the dangers we believe we are relatively safe for the time being.");
                CommandResult.WriteLine("Since we cannot yet safely erradicate the exotic particles from our planet we have taken to doing the next best thing, and that is embracing the Niantic Project. We are still corroborating claims made by Niantic about an alien race known only as \"Shapers\", but the technology developed by Niantic does appear to have the ability to safely manipulate XM particles and stable Omega structures.");
                CommandResult.WriteLine("As an agent of the resistance you already know how to use this technology and we encourage you to continue to do so. However, as part of the Omega Directive we require that you cooperate with fellow Omega agents only for any serious task. Until an agent is a verified member of Omega you have every reason to distrust them, even if they claim to be part of the resistance.");
                CommandResult.WriteLine();
                CommandResult.WriteLine("We are glad to have you as a verified Omega agent, {0}. We hope you will help us keep as many stable structures out of enemy hands as possible. For now, it is our only defense.", CommandResult.CurrentUser.Username);
            }
        }