Official Everybody Edits Forums

Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?

You are not logged in.

#1 2015-08-12 23:40:06

Cyral
Member
From: United States
Joined: 2015-02-15
Posts: 2,269

[Release] [Library] Command Parser

I made this library a while back for use in my own server programs and games that require user input via commands. Thought some of you might find it useful.

The Command Parser Framework makes it easy to create commands with optional and required arguments, grouped parameters, validation rules, permission levels, and more.

You can make commands return errors if they are not filled out completely, and also suggest commands in case of a misspelling.

command-parser.png

Example:

This command enables a module of a bot. It uses the enum/option functionality to limit the parameter to a set of values. If snakebot is specified, a block parameter must also be accompanied (such as !enable snakebot red).

Parser = CommandParser
    .CreateNew()
    .UsePrefix("!")
    .OnError((o, error) => OnParseError(o, error));

Parser.AddCommand(Command
    .Create("Enable")
    .AddAlias("enable", "en")
    .SetDescription("Enable a module of the bot.")
    .SetAction((arguments, data) =>
    {
        var module = arguments.FromName("module");
        // TODO: Actually do something
        Console.WriteLine(module + " enabled!");
    })
    .AddArgument(Argument
        .Create("module")
        .AddOption(Argument.Create("snakebot")
           .AddArgument(Argument.Create("block")))
        .AddOption(Argument.Create("digbot"))
        .AddOption(Argument.Create("guestkicker"))
        .SetDefault("snakebot")
    ));

The command can then be used as:

WKYOu7.png
(This is just a sample application. The commands would be accessible through EE chat if you called Parser.Parse(message) when a chat is received)

Links
  - Project Page
  - GitHub
  - Tutorial & Docs

It can be downloaded from the latest release on GitHub. You can also install it through NuGet with: Install-Package Pyratron.Frameworks.Commands.Parser

Command-Parser.svg?branch=master


Player Since 2011. I used to make bots and stuff.

Offline

Wooted by: (2)

#2 2015-08-13 16:28:07

John
Member
Joined: 2019-01-11
Posts: 2,011

Re: [Release] [Library] Command Parser

Neat! I think I may try that out. Thanks buddy!


PW?scale=2

Offline

#3 2015-08-13 20:35:55

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: [Release] [Library] Command Parser

Very nice lib, kudos to you, might look into the source if you don't mind.

Offline

#4 2015-08-14 02:02:36

Cyral
Member
From: United States
Joined: 2015-02-15
Posts: 2,269

Re: [Release] [Library] Command Parser

den3107 wrote:

Very nice lib, kudos to you, might look into the source if you don't mind.

Thanks. It's on GitHub for a reason //forums.everybodyedits.com/img/smilies/smile


Player Since 2011. I used to make bots and stuff.

Offline

#5 2015-08-29 21:31:16

Cyral
Member
From: United States
Joined: 2015-02-15
Posts: 2,269

Re: [Release] [Library] Command Parser

Wrote a small library to go along with this: https://github.com/Pyratron/LogConsole

There are already a lot of logging libraries out there, but I needed this to make it so commands can be typed in the console while data is being logged. (For example, writing chat messages to the console without overwriting what you have written)


Player Since 2011. I used to make bots and stuff.

Offline

Wooted by:
Cyral1440880276536226

Board footer

Powered by FluxBB

[ Started around 1732784339.3164 - Generated in 0.038 seconds, 12 queries executed - Memory usage: 1.44 MiB (Peak: 1.55 MiB) ]