From 898e98ea0641cd0f3ab999f520ed190ba4856106 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 26 Nov 2015 15:37:00 +0100 Subject: [PATCH] Added new code --- docs/samples/command.cs | 26 ++++++--------- docs/samples/command_group.cs | 41 ++++++++++++------------ docs/samples/command_service_creation.cs | 9 ++++++ 3 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 docs/samples/command_service_creation.cs diff --git a/docs/samples/command.cs b/docs/samples/command.cs index 2dfb8e549..d32e216c3 100644 --- a/docs/samples/command.cs +++ b/docs/samples/command.cs @@ -1,16 +1,10 @@ -public enum Permissions -{ - User, - Moderator, - Admin -} - -//Usage: say [text] -client.CreateCommand("say") - .ArgsEqual(1) - .MinPermissions((int)Permissions.User) - .Do(async e => - { - string msg = Format.Normal(e.CommandText); - await _client.SendMessage(e.Channel, msg); - }); \ No newline at end of file +//Since we have setup our CommandChar to be '~', we will run this command by typing ~greet +commands.CreateCommand("greet") //create command greet + .Alias(new string[] { "gr", "hi" }) //add 2 aliases, so it can be run with ~gr and ~hi + .Description("Greets a person.") //add description, it will be shown when ~help is used + .Parameter("GreetedPerson", ParameterType.Required) //as an argument, we have a person we want to greet + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson")); + //sends a message to channel with the given text + }); \ No newline at end of file diff --git a/docs/samples/command_group.cs b/docs/samples/command_group.cs index b49b87d94..5610723be 100644 --- a/docs/samples/command_group.cs +++ b/docs/samples/command_group.cs @@ -1,20 +1,21 @@ -client.CreateCommandGroup("invites", invites => -{ - invites.DefaultMinPermissions((int)Permissions.Admin); - - //Usage: invites accept [inviteCode] - invites.CreateCommand("accept") - .ArgsEqual(1) - .Do(async e => - { - try - { - await _client.AcceptInvite(e.Args[0]); - await _client.SendMessage(e.Channel, "Invite \"" + e.Args[0] + "\" accepted."); - } - catch (HttpException ex) - { - await _client.SendMessage(e.Channel, "Error: " + ex.Message); - } - }); -}); \ No newline at end of file +//we would run our commands with ~do greet X and ~do bye X +commands.CreateGroup("do", cgb => + { + cgb.CreateCommand("greet") + .Alias(new string[] { "gr", "hi" }) + .Description("Greets a person.") + .Parameter("GreetedPerson", ParameterType.Required) + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " greets " + e.GetArg("GreetedPerson")); + }); + + cgb.CreateCommand("bye") + .Alias(new string[] { "bb", "gb" }) + .Description("Greets a person.") + .Parameter("GreetedPerson", ParameterType.Required) + .Do(async e => + { + await client.SendMessage(e.Channel, e.User.Name + " says goodbye to " + e.GetArg("GreetedPerson")); + }); + }); \ No newline at end of file diff --git a/docs/samples/command_service_creation.cs b/docs/samples/command_service_creation.cs new file mode 100644 index 000000000..013619ff5 --- /dev/null +++ b/docs/samples/command_service_creation.cs @@ -0,0 +1,9 @@ +//create command service +var commandService = new CommandService(new CommandServiceConfig +{ + CommandChar = '~', // prefix char for commands + HelpMode = HelpMode.Public +}); + +//add command service +var commands = client.AddService(commandService); \ No newline at end of file