コード例 #1
0
        public void TestHelp()
        {
            string expected = "Select an item to interact with by typing the text contained by one set of square brackets";
            string actual   = HelpMessage.Help();

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public HelpMessage CreateCommandHelp(CommandDescriptor command, IReadOnlyList <CommandDescriptor> subCommandStack)
        {
            var help = new HelpMessage();

            // Usage
            help.Children.Add(new HelpSection(HelpSectionId.Usage, new HelpUsage($"Usage: {CreateUsageCommandOptionsAndArgs(command, subCommandStack)}")));

            // Description
            if (!string.IsNullOrWhiteSpace(command.Description))
            {
                help.Children.Add(new HelpSection(HelpSectionId.Description, new HelpDescription(command.Description)));
            }

            // Arguments
            AddHelpForCommandArguments(help, command.Arguments);

            // Options
            AddHelpForCommandOptions(help, command.Options.OfType <ICommandOptionDescriptor>().Concat(command.OptionLikeCommands));

            // Transform help document
            var transformers = FilterHelper.GetFilters <ICoconaHelpTransformer>(command.Method, _serviceProvider);

            foreach (var transformer in transformers)
            {
                transformer.TransformHelp(help, command);
            }

            return(help);
        }
コード例 #3
0
ファイル: CoconaHelpRenderer.cs プロジェクト: kimozex/Cocona
        public string Render(HelpMessage message)
        {
            var ctx = new CoconaHelpRenderingContext();

            RenderContent(ctx, message);
            return(ctx.StringBuilder.ToString());
        }
コード例 #4
0
        public void HelpMessage_InvalidSubcommand()
        {
            var subCommand = "invalidOne";
            var ex         = Assert.Throws <ArgumentNullException>(() => HelpMessage.subCommand(subCommand));

            Assert.Contains($"Unknown help for subcommand '{subCommand}'.", ex.Message);
        }
コード例 #5
0
 private void AddHelpForCommandOptions(HelpMessage help, IEnumerable <ICommandOptionDescriptor> options)
 {
     if (options.Any(x => !x.Flags.HasFlag(CommandOptionFlags.Hidden)))
     {
         help.Children.Add(new HelpSection(HelpSectionId.Options,
                                           new HelpHeading("Options:"),
                                           new HelpSection(
                                               new HelpLabelDescriptionList(
                                                   options
                                                   .Where(x => !x.Flags.HasFlag(CommandOptionFlags.Hidden))
                                                   .Select((x, i) =>
                                                           x is CommandOptionDescriptor option
                                 ? new HelpLabelDescriptionListItem(
                                                               BuildParameterLabel(option),
                                                               BuildParameterDescription(x.Description, option.IsRequired, option.OptionType, option.DefaultValue)
                                                               )
                                 : x is CommandOptionLikeCommandDescriptor optionLikeCommand
                                     ? new HelpLabelDescriptionListItem(
                                                               BuildParameterLabel(optionLikeCommand),
                                                               optionLikeCommand.Description
                                                               )
                                     : throw new NotSupportedException()
                                                           )
                                                   .ToArray()
                                                   )
                                               )
                                           ));
     }
 }
コード例 #6
0
 public void HelpMessage_ExistsForEachSubcommand()
 {
     foreach (var subCommand in HelpMessage.supportedSubCommands)
     {
         var helpResponse = HelpMessage.subCommand(subCommand);
         Assert.Contains(helpResponse, s => s.Contains($"{subCommand} help"));
     }
 }
コード例 #7
0
    // Use this for initialization
    void Awake()
    {
        Instance = this;
        _text = GetComponentInChildren<Text>();
        _panel = GetComponentInChildren<Image>();

        textColor = _text.color;
        panelColor = _panel.color;
    }
コード例 #8
0
 void Clear(HelpMessage help, ValidationError error)
 {
     helpString           = help.Msg();
     errorString          = error != ValidationError.None ? error.Msg() : null;
     m_uniqueMaterials    = new Material[] { };
     m_duplicateMaterials = new MaterialList[] { };
     m_excludes.Clear();
     isValid = false;
 }
コード例 #9
0
ファイル: EmployeesBL.cs プロジェクト: PeerCohen/finalProject
        public static void addmessageForHelp(string message, int num)
        {
            List <HelpMessage> messageList = new List <HelpMessage>();
            var m = new HelpMessage();

            m.message  = message;
            m.numTable = num;
            messageList.Add(m);
        }
コード例 #10
0
        public void HelpMessage_ExistsForApplication()
        {
            var helpResponse = HelpMessage.application();

            Assert.Contains(helpResponse, s => s.Contains("Usage"));
            foreach (var subCommand in HelpMessage.supportedSubCommands)
            {
                Assert.Contains(helpResponse, s => s.Contains($"{subCommand} help"));
            }
        }
コード例 #11
0
        public void RenderTest_Section()
        {
            var message = new HelpMessage(
                new HelpSection(
                    new HelpParagraph("1st")
                    )
                );

            new CoconaHelpRenderer().Render(message).Should().Be(@"
1st
".TrimStart());
        }
コード例 #12
0
        public static void Main(string[] args)
        {
            Console.CancelKeyPress += OnProcessExit;
            LoadSettings();

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Is(Enum.Parse <LogEventLevel>(_settings.Options.LogLevel))
                         .WriteTo.Console()
                         .CreateLogger();

            var core = new BotCore(_settings);

            core.EnableCaching <LevelCache>();
            core.EnableAssemblyLocalization();

            core.RegisterController <TelegramController>();
            core.RegisterController <VkController>();
            core.RegisterController <DiscordController>();

            var commands = core.RegisterModule <CommandsModule>();

            commands.RegisterConverter <UserConverter>();
            commands.RegisterConverter <ChatConverter>();
            commands.RegisterConverter <RouteConverter>();

            var router = core.Router;

            router.AddHandler <PrimaryMiddleware>();
            router.AddHandler <UsersMiddleware>();
            router.AddHandler <ReplicatingMiddleware>();

            router.AddHandler <TestCommand>();
            router.AddHandler <SudoCommand>();
            router.AddHandler <ChatsCommand>();
            router.AddHandler <UsersCommand>();
            router.AddHandler <RoutesCommand>();
            router.AddHandler <HelpCommand>();

            HelpMessage.Init(commands.GetCommands());
            core.Start();
            Core = core;

            CreateAdmins();

            if (Options.Changelog)
            {
                BroadcastChangelog();
            }

            Log.Information("Replica started");

            Thread.Sleep(Timeout.Infinite);
        }
コード例 #13
0
ファイル: WebService.asmx.cs プロジェクト: FrankMi101/ASM
        public string GetHelpContentByHelpPara(string operation, HelpMessage parameter)
        {
            try
            {
                //  string sp = "dbo.SIC_sys_HelpContent";

                return(ValueData.GeneralValue <string>("AppsPageHelp", "HelpContent", parameter));
            }
            catch (Exception ex)
            {
                var em = ex.Message;
                return("");
            }
        }
コード例 #14
0
 private async Task <bool> SendMessage()
 {
     if (HelpMessage != null)
     {
         await HelpMessage.ModifyAsync(msg =>
         {
             msg.Embed = HelpMessageEmbed;
         });
     }
     else
     {
         HelpMessage = await Channel.SendMessageAsync(string.Empty, embed : HelpMessageEmbed);
     }
     return(true);
 }
コード例 #15
0
ファイル: ControlManager.cs プロジェクト: deckerbd/TS3-Bot
        /// <summary>
        /// Receives the Help message
        /// </summary>
        /// <param name="message">The message.</param>
        private void Execute(HelpMessage message)
        {
            var helpMessages = MessageHelper.GetHelpMessages(Repository.Client.GetClientInfo(message.SenderClientId).ServerGroups);

            if (helpMessages != null)
            {
                helpMessages.ForEach(helpMessage => QueryRunner.SendTextMessage(Repository.Settings.Control.Help.Target, Repository.Settings.Control.Help.TargetId > 0 ? Repository.Settings.Control.Help.TargetId : message.SenderClientId,
                                                                                helpMessage.ToMessage()));
            }

            var clientEntry = Repository.Client.GetClientInfo(message.SenderClientId);

            Log(Repository.Settings.Control.Help,
                string.Format("Client '{1}'(id:{2}) used {0}.", Repository.Settings.Control.Help.Command,
                              clientEntry.Nickname, clientEntry.DatabaseId));
        }
コード例 #16
0
ファイル: Player.cs プロジェクト: SandSquare/bombermouse
    void Start()
    {
        legalMove = true;
        movement  = GetComponent <Movement>();

        helpMessageUI = GameObject.Find("HelpMessageUI")?.GetComponent <HelpMessage>();

        levelInfo         = LevelInfo.instance;
        explosionLength   = levelInfo.explosionLength;
        currentBombAmount = levelInfo.bombAmount;

        for (int i = 0; i < levelInfo.bombAmount; i++)
        {
            bombList.Add(ObjectColors.Normal);
        }

        UpdateBombAmounts();
    }
コード例 #17
0
 private void AddHelpForCommandArguments(HelpMessage help, IEnumerable <CommandArgumentDescriptor> arguments)
 {
     if (arguments.Any())
     {
         help.Children.Add(new HelpSection(HelpSectionId.Arguments,
                                           new HelpHeading("Arguments:"),
                                           new HelpSection(
                                               new HelpLabelDescriptionList(
                                                   arguments
                                                   .Select((x, i) =>
                                                           new HelpLabelDescriptionListItem(
                                                               $"{i}: {x.Name}",
                                                               BuildParameterDescription(x.Description, x.IsRequired, x.ArgumentType, x.DefaultValue)
                                                               )
                                                           )
                                                   .ToArray()
                                                   )
                                               )
                                           ));
     }
 }
コード例 #18
0
        public void RenderTest_Section_Nested_Indent_NoSpacing()
        {
            var message = new HelpMessage(
                new HelpSection(
                    new HelpHeading("1st")
                    ),
                new HelpSection(
                    new HelpHeading("2nd"),
                    new HelpSection(
                        new HelpParagraph("3rd")
                        )
                    )
                );

            new CoconaHelpRenderer().Render(message).Should().Be(@"
1st

2nd
  3rd
".TrimStart());
        }
コード例 #19
0
        public override void TransformHelp(HelpMessage helpMessage, CommandDescriptor command)
        {
            var descSection = (HelpSection)helpMessage.Children.First(x => x is HelpSection section && section.Id == HelpSectionId.Description);

            descSection.Children.Add(new HelpPreformattedText(@"
  ________ 
 < Hello! >
  -------- 
         \   ^__^
          \  (oo)\_______
             (__)\       )\/\
                 ||----w |
                 ||     ||
"));

            helpMessage.Children.Add(new HelpSection(
                                         new HelpHeading("Example:"),
                                         new HelpSection(
                                             new HelpParagraph("MyApp --foo --bar")
                                             )
                                         ));
        }
コード例 #20
0
        public void RenderTest_LabelDescriptionList()
        {
            var message = new HelpMessage(
                new HelpSection(
                    new HelpHeading("Usage: ConsoleApp1")
                    ),
                new HelpSection(
                    new HelpParagraph("description of an application")
                    ),
                new HelpSection(
                    new HelpHeading("Options:"),
                    new HelpSection(
                        new HelpLabelDescriptionList(
                            new HelpLabelDescriptionListItem("--foo, -f", "Foo option (Required)"),
                            new HelpLabelDescriptionListItem("--looooooong-option, -l", "Long name option")
                            )
                        )
                    ),
                new HelpSection(
                    new HelpHeading("Examples:"),
                    new HelpSection(
                        new HelpParagraph("ConsoleApp1 --foo --bar")
                        )
                    )
                );

            new CoconaHelpRenderer().Render(message).Should().Be(@"
Usage: ConsoleApp1

description of an application

Options:
  --foo, -f                  Foo option (Required)
  --looooooong-option, -l    Long name option

Examples:
  ConsoleApp1 --foo --bar
".TrimStart());
        }
コード例 #21
0
        public HelpMenu(IMessageChannel channel)
        {
            Channel = channel;

            GetTabs();

            HelpMessageEmbed = Tabs.Where(tab => tab.Value.Title == "General").First().Value;

            bool success = SendMessage().Result;

            SetupListener();

            var timer = new Timer(1000 * 60 * 10);

            timer.Elapsed += async(_, __) =>
            {
                await HelpMessage.RemoveAllReactionsAsync();

                Listener?.Dispose();
                timer.Dispose();
            };
        }
コード例 #22
0
 private void AddHelpForCommandOptions(HelpMessage help, IEnumerable <CommandOptionDescriptor> options)
 {
     if (options.Any(x => !x.IsHidden))
     {
         help.Children.Add(new HelpSection(HelpSectionId.Options,
                                           new HelpHeading("Options:"),
                                           new HelpSection(
                                               new HelpLabelDescriptionList(
                                                   options
                                                   .Where(x => !x.IsHidden)
                                                   .Select((x, i) =>
                                                           new HelpLabelDescriptionListItem(
                                                               BuildParameterLabel(x),
                                                               BuildParameterDescription(x.Description, x.IsRequired, x.OptionType, x.DefaultValue)
                                                               )
                                                           )
                                                   .ToArray()
                                                   )
                                               )
                                           ));
     }
 }
コード例 #23
0
ファイル: GameController.cs プロジェクト: tdm1223/WildLife
    void Start()
    {
        GameOverPanel    = UICanvas.transform.Find("GameOverPanel").gameObject;
        BigWildSpawnText = UICanvas.transform.Find("BigWildSpawnPanel/BigWildSpawnText").GetComponent <Text>();
        MessageText      = UICanvas.transform.Find("MessagePanel/MessageText").GetComponent <Text>();
        HelpMessage      = GetComponent <HelpMessage>();

        RightActionMessagePanel = UICanvas.transform.Find("ActionMessagePanel/RightActionMessagePanel").gameObject;
        WrongActionMessagePanel = UICanvas.transform.Find("ActionMessagePanel/WrongActionMessagePanel").gameObject;
        ClockText = UICanvas.transform.Find("ClockPanel/ClockText").GetComponent <Text>();
        Audio     = GetComponent <GameAudio>();

        if (NetworkServer.connections.Count == 1)
        {
            isSinglePlay = true;
            survivors    = new GameObject[1];
            survivors[0] = GameObject.FindGameObjectsWithTag("Player")[0].gameObject;

            BigWildSpawnManager.StartBigWildSpawn();
            WriteMessageText("최대한 오래 살아남으세요!");
            StartClock();
        }
    }
コード例 #24
0
        public void RenderTest_Preformatted()
        {
            var message = new HelpMessage(
                new HelpSection(
                    new HelpParagraph("preformatted text"),
                    new HelpSection(
                        new HelpPreformattedText("using System;\r\n\r\nclass Program\r\n{\r\n    static void Main(string[] args)\r\n    {\r\n        Console.WriteLine(123);\r\n    }\r\n}")
                        )
                    )
                );

            new CoconaHelpRenderer().Render(message).Should().Be(@"
preformatted text
  using System;
  
  class Program
  {
      static void Main(string[] args)
      {
          Console.WriteLine(123);
      }
  }
".TrimStart());
        }
コード例 #25
0
        /// <summary>
        /// Parses the specified Grbl message.
        /// </summary>
        /// <param name="message">The Grbl message string.</param>
        /// <returns></returns>
        public static GrblMessage Parse(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentNullException("message");
            }

            GrblMessage msg = null;

            if (message == "ok")
            {
                msg = new OkMessage();
            }
            else if (message.StartsWith("error:"))
            {
                msg = new ErrorMessage();
            }
            else if (message.StartsWith("<") && message.EndsWith(">"))
            {
                msg = new StatusReportMessage();
            }
            else if (message.StartsWith("Grbl "))
            {
                msg = new WelcomeMessage();
            }
            else if (message.StartsWith("ALARM:"))
            {
                msg = new AlarmMessage();
            }
            else if (message.StartsWith("$"))
            {
                msg = new SettingsPrintoutMessage();
            }
            else if (message.StartsWith("[MSG:"))
            {
                msg = new NonQueriedFeedbackMessage();
            }
            else if (message.StartsWith("[GC:"))
            {
                msg = new GcodeParserStateMessage();
            }
            else if (message.StartsWith("[HLP:"))
            {
                msg = new HelpMessage();
            }
            else if (message.StartsWith("[G5") ||
                     message.StartsWith("[G28:") ||
                     message.StartsWith("[G30:") ||
                     message.StartsWith("[G92:"))
            {
                msg = new CoordinateSettingMessage();
            }
            else if (message.StartsWith("[PRB:"))
            {
                msg = new ProbeSettingMessage();
            }
            else if (message.StartsWith("[TLO:"))
            {
                msg = new ToolLengthOffsetMessage();
            }
            else if (message.StartsWith("[VER:"))
            {
                msg = new VersionMessage();
            }
            else if (message.StartsWith("[OPT:"))
            {
                msg = new CompileOptionPrintoutMessage();
            }
            else if (message.StartsWith("[echo:"))
            {
                msg = new EchoMessage();
            }
            else if (message.StartsWith(">"))
            {
                msg = new StartupLineResponseMessage();
            }
            else
            {
                msg = new UnknownMessage();
            }
            msg.MessageBody = message;
            msg.OnLoadMessage(message);
            return(msg);
        }
コード例 #26
0
ファイル: AppsPageHelp.cs プロジェクト: FrankMi101/SIC
 public static string PageHelp(string action, HelpMessage parameter)
 {
     parameter.Operate = action;
     return(CommonValue <string>(action, parameter));
 }
コード例 #27
0
 // Use this for initialization
 void Start()
 {
     instance = this;
     helpText = gameObject.GetComponent <Text> ();
 }
コード例 #28
0
 public void TransformHelp(HelpMessage helpMessage, CommandDescriptor command)
 {
     helpMessage.Children.Add(new HelpSection(new HelpHeading("Hello, Konnichiwa!")));
 }
コード例 #29
0
ファイル: Bot.cs プロジェクト: sanjayradadiya/SkypeBot
        void skype_MessageStatus(ChatMessage pMessage, TChatMessageStatus Status)
        {
            MessageEvent messageevent = new MessageEvent(pMessage, Status);

            //Now, we shoot our shit here.
            if (Status == TChatMessageStatus.cmsSending)
            {
                try
                {
                    if (!MessageReceived.Invoke(this, messageevent))
                    {
                        Logger.Log(string.Format(Utils.XOR("ତୄଛ଻ହଲଔ଎ତ଍ଥହ଒ଢ଄େଠଳଽ଻ହଲୃ଎ତ଍ଥ଻଒ଢ଄େତଳଽ଻ହଲ୆ୂତ଍ଥମ଺ଜ଄େମଣଽ଻ହ଱ଐ଎ତ଍ଥଏ଒ଢ଄େ଒ଯଛ଻ହିଓୂତ଍ଦ଎଒ଢ଄େଖୄଛ଻ହରଃୂତ଍ଥୂ଒ଢ଄େହଙଛ଻ହ଱ଐ଎ତ଍ଥୁ଒ଢ଄େ଒ଯଛ଻ହ଴ଃୂତ଍ଦ୆଒ଢ଄େ଒ଯଛ଻ହିଇୂତ଍ଥ଍଒ଢ଄େ", 619580279), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                        return;
                    }
                }
                catch { }
                Logger.LogMessage(string.Format(Utils.XOR("昪昕昔昏昶昭昌昌昛昼昮昽昙映昹晉是是晉昏昶昭昶昌昛昼昮昿昙映昹晉昫昕晉昏昶昭昪昈昛昼昮昢昚映昹晉昚昿昔昏昶昭昢昈昛昼昮昲昚映昹晉昪昿昔昏昶是昈昈昛昼昮昢昚映昹晉昮昕晉昏昶昮昔昌昛昼昮昋昙映昹晉昷是昔昏昶昫晁昈昛昼昭晉昙映昹晉昛昕昔昏昶映昲昈昛昼昭晍昙映昹晉昵是昔昏昶是昈昈昛昼昭晅", 1355376248), (pMessage.Chat.Topic == "" ? pMessage.Sender.FullName : pMessage.Chat.Topic), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                //invoke all stuffs
                if (pMessage.Body == "" || pMessage.Body[0].ToString() != bot.CommandDelimiter || pMessage.Body.ToString() == bot.CommandDelimiter)
                {
                    //pMessage.Chat.SendMessage(InvalidMessage.Invoke(this, messageevent));
                    return;
                }
                //Check the incoming command against the existing command list.
                List <string> args = Utils.ParseParameters(pMessage.Body.ToString());
                if (args[0] == string.Format(Utils.XOR("嬡嬨嬜嬘嬾嬧嬾孅嬩嬤嬦嬧嬕嬧嬵孁嬧嬨嬜嬘嬾嬥孅孅嬩嬤嬦嬲嬽嬝嬵孁嬤嬸嬜嬘嬾嬡孍孍", 1244617584), bot.CommandDelimiter))
                {
                    //Execute defined help message.
                    try
                    {
                        pMessage.Chat.SendMessage(HelpMessage.Invoke(this, messageevent));
                    }
                    catch { }
                    for (int i = 0; i < commands.help.Count; i++)
                    {
                        pMessage.Chat.SendMessage(bot.CommandDelimiter + commands.help[i]);
                    }
                    return;
                }
                if (commands.sendhandlers.ContainsKey(string.Format("{0}", args[0].Substring(1))))
                {
                    Logger.Log(string.Format(Utils.XOR("", 132183750), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                    //Create a new instance of the message handler.
                    new Thread(new ThreadStart(delegate()
                    {
                        BotCommandSent v = Activator.CreateInstance(commands.sendhandlers[args[0].Substring(1)]) as BotCommandSent;
                        if (v.NumberOfArgs + 1 != args.Count)
                        {
                            pMessage.Chat.SendMessage(bot.CommandDelimiter + "Usage: " + v.Usage); return;
                        }
                        string output = v.Handle(pMessage, args.ToArray());
                        if (output != null && output != "")
                        {
                            pMessage.Chat.SendMessage(output);
                        }
                    })).Start();
                    return;
                }
                else
                {
                    try
                    {
                        //Didn't do jack shit. Send help message invoke?
                        //pMessage.Chat.SendMessage(InvalidMessage.Invoke(this, messageevent));
                    }
                    catch { }
                }
            }
            if (Status == TChatMessageStatus.cmsReceived) //Make sure the message is receiving
            {
                try
                {
                    if (!MessageReceived.Invoke(this, messageevent))
                    {
                        Logger.Log(string.Format(Utils.XOR("ତୄଛ଻ହଲଔ଎ତ଍ଥହ଒ଢ଄େଠଳଽ଻ହଲୃ଎ତ଍ଥ଻଒ଢ଄େତଳଽ଻ହଲ୆ୂତ଍ଥମ଺ଜ଄େମଣଽ଻ହ଱ଐ଎ତ଍ଥଏ଒ଢ଄େ଒ଯଛ଻ହିଓୂତ଍ଦ଎଒ଢ଄େଖୄଛ଻ହରଃୂତ଍ଥୂ଒ଢ଄େହଙଛ଻ହ଱ଐ଎ତ଍ଥୁ଒ଢ଄େ଒ଯଛ଻ହ଴ଃୂତ଍ଦ୆଒ଢ଄େ଒ଯଛ଻ହିଇୂତ଍ଥ଍଒ଢ଄େ", 619580279), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                        return;
                    }
                }
                catch { }
                Logger.LogMessage(string.Format(Utils.XOR("昪昕昔昏昶昭昌昌昛昼昮昽昙映昹晉是是晉昏昶昭昶昌昛昼昮昿昙映昹晉昫昕晉昏昶昭昪昈昛昼昮昢昚映昹晉昚昿昔昏昶昭昢昈昛昼昮昲昚映昹晉昪昿昔昏昶是昈昈昛昼昮昢昚映昹晉昮昕晉昏昶昮昔昌昛昼昮昋昙映昹晉昷是昔昏昶昫晁昈昛昼昭晉昙映昹晉昛昕昔昏昶映昲昈昛昼昭晍昙映昹晉昵是昔昏昶是昈昈昛昼昭晅", 1355376248), (pMessage.Chat.Topic == "" ? pMessage.Sender.FullName : pMessage.Chat.Topic), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                //If the user is blocked then just f**k him up and ignore ALL shit.
                if (pMessage.Sender.IsBlocked)
                {
                    return;
                }
                //If the message sender is set to ignore, then just ignore the F**K outta him.
                if (Ignore.Contains(pMessage.Sender.Handle))
                {
                    try
                    {
                        pMessage.Chat.SendMessage(IgnoredMessage.Invoke(this, messageevent));
                    }
                    catch { }
                    return;
                }
                if (pMessage.Body[0].ToString() != bot.CommandDelimiter || pMessage.Body.ToString() == bot.CommandDelimiter)
                {
                    //pMessage.Chat.SendMessage(InvalidMessage.Invoke(this, messageevent));
                    return;
                }
                //Check the incoming command against the existing command list.
                List <string> args = Utils.ParseParameters(pMessage.Body.ToString());
                if (args[0] == string.Format(Utils.XOR("嬡嬨嬜嬘嬾嬧嬾孅嬩嬤嬦嬧嬕嬧嬵孁嬧嬨嬜嬘嬾嬥孅孅嬩嬤嬦嬲嬽嬝嬵孁嬤嬸嬜嬘嬾嬡孍孍", 1244617584), bot.CommandDelimiter))
                {
                    //Execute defined help message.
                    try
                    {
                        pMessage.Chat.SendMessage(HelpMessage.Invoke(this, messageevent));
                    }
                    catch { }
                    for (int i = 0; i < commands.help.Count; i++)
                    {
                        pMessage.Chat.SendMessage(bot.CommandDelimiter + commands.help[i]);
                    }
                    return;
                }
                if (commands.handlers.ContainsKey(string.Format("{0}", args[0].Substring(1))))
                {
                    Logger.Log(string.Format(Utils.XOR("", 132183750), pMessage.Sender.Handle, pMessage.Body.ToString().Replace("\n", "")));
                    //Create a new instance of the message handler.
                    new Thread(new ThreadStart(delegate()
                    {
                        BotCommand v = Activator.CreateInstance(commands.handlers[args[0].Substring(1)]) as BotCommand;
                        if (v.NumberOfArgs + 1 != args.Count)
                        {
                            pMessage.Chat.SendMessage(bot.CommandDelimiter + v.Usage); return;
                        }
                        string output = v.Handle(pMessage, args.ToArray());
                        if (output != null && output != "")
                        {
                            pMessage.Chat.SendMessage(output);
                        }
                    })).Start();
                    return;
                }
                else
                {
                    try
                    {
                        //Didn't do jack shit. Send help message invoke?
                        pMessage.Chat.SendMessage(InvalidMessage.Invoke(this, messageevent));
                    }
                    catch { }
                }
            }
        }
コード例 #30
0
 public override void TransformHelp(HelpMessage helpMessage, CommandDescriptor command)
 {
     helpMessage.Children.Add(new HelpSection(new HelpHeading("Hi!")));
 }
コード例 #31
0
        public HelpMessage CreateCommandsIndexHelp(CommandCollection commandCollection, IReadOnlyList <CommandDescriptor> subCommandStack)
        {
            var help = new HelpMessage();

            // Usage
            var usageSection     = new HelpSection(HelpSectionId.Usage);
            var subCommandParams = (subCommandStack.Count > 0) ? string.Join(" ", subCommandStack.Select(x => x.Name)) + " " : "";

            if (commandCollection.All.Count != 1)
            {
                usageSection.Children.Add(new HelpUsage($"Usage: {_applicationMetadataProvider.GetExecutableName()} {subCommandParams}[command]"));
            }
            if (commandCollection.Primary != null && (commandCollection.All.Count == 1 || commandCollection.Primary.Options.Any() || commandCollection.Primary.Arguments.Any()))
            {
                usageSection.Children.Add(new HelpUsage($"Usage: {CreateUsageCommandOptionsAndArgs(commandCollection.Primary, subCommandStack)}"));
            }
            help.Children.Add(usageSection);

            // Description
            var description = !string.IsNullOrWhiteSpace(commandCollection.Description)
                ? commandCollection.Description
                : !string.IsNullOrWhiteSpace(commandCollection.Primary?.Description)
                    ? commandCollection.Primary?.Description
                    : !string.IsNullOrWhiteSpace(_applicationMetadataProvider.GetDescription())
                        ? _applicationMetadataProvider.GetDescription()
                        : string.Empty;

            if (!string.IsNullOrWhiteSpace(description))
            {
                help.Children.Add(new HelpSection(HelpSectionId.Description, new HelpDescription(description !)));
            }

            // Commands
            var commandsExceptPrimary = commandCollection.All.Where(x => !x.IsPrimaryCommand && !x.IsHidden).ToArray();

            if (commandsExceptPrimary.Any())
            {
                help.Children.Add(new HelpSection(HelpSectionId.Commands,
                                                  new HelpHeading("Commands:"),
                                                  new HelpSection(
                                                      new HelpLabelDescriptionList(
                                                          commandsExceptPrimary
                                                          .Select((x, i) =>
                                                                  new HelpLabelDescriptionListItem(x.Name, x.Description)
                                                                  )
                                                          .ToArray()
                                                          )
                                                      )
                                                  ));
            }

            // Show helps for primary command.
            if (commandCollection.Primary != null)
            {
                // Arguments
                AddHelpForCommandArguments(help, commandCollection.Primary.Arguments);

                // Options
                AddHelpForCommandOptions(help, commandCollection.Primary.Options.OfType <ICommandOptionDescriptor>().Concat(commandCollection.Primary.OptionLikeCommands));
            }

            // Transform help document
            if (commandCollection.Primary != null)
            {
                var transformers = FilterHelper.GetFilters <ICoconaHelpTransformer>(commandCollection.Primary.Method, _serviceProvider);

                // TODO: This is ad-hoc workaround for default primary command.
                if (BuiltInPrimaryCommand.IsBuiltInCommand(commandCollection.Primary))
                {
                    transformers = commandCollection.All
                                   .Select(x => x.CommandType)
                                   .Distinct()
                                   .SelectMany(x => FilterHelper.GetFilters <ICoconaHelpTransformer>(x, _serviceProvider))
                                   .ToArray();
                }

                foreach (var transformer in transformers)
                {
                    transformer.TransformHelp(help, commandCollection.Primary);
                }
            }

            return(help);
        }
コード例 #32
0
        /// <summary>
        /// Receives the Help message
        /// </summary>
        /// <param name="message">The message.</param>
        private void Execute(HelpMessage message)
        {
            var helpMessages = MessageHelper.GetHelpMessages(Repository.Client.GetClientInfo(message.SenderClientId).ServerGroups);
            if (helpMessages != null)
            {
                helpMessages.ForEach(helpMessage => QueryRunner.SendTextMessage(Repository.Settings.Control.Help.Target, Repository.Settings.Control.Help.TargetId > 0 ? Repository.Settings.Control.Help.TargetId : message.SenderClientId,
                    helpMessage.ToMessage()));
            }

            var clientEntry = Repository.Client.GetClientInfo(message.SenderClientId);
            Log(Repository.Settings.Control.Help,
                string.Format("Client '{1}'(id:{2}) used {0}.", Repository.Settings.Control.Help.Command,
                              clientEntry.Nickname, clientEntry.DatabaseId));
        }