Exemple #1
0
        static Commands()
        {
            CommandsList = new Dictionary<string, BotCommand>();

            CommandsList["source"] = new BotCommand("https://github.com/JaxForReal/HackBotCSharp/");

            CommandsList["help"] = new BotCommand(
                "Displays general help or help about a specific command.\nUsage: help <command name>",
                args => {
                    //if no args supplied, list all commands
                    if (args.Args.Length == 0) {
                        args.Bot.Client.SendChat(
                        "A hack.chat bot by @Jax.\nCommands:\n:" +
                        args.Bot.Commands.Keys.Aggregate((total, next) => total + ", " + args.Bot.Config.CommandTrigger + next) +
                        "\nSource is at https://github.com/JaxForReal/HackBotCSharp/");
                    //else, get help for a specific command
                    } else {
                        //args.Args[0] is the anme of requested command for help
                        args.Bot.Client.SendChat("Help for " + args.Args[0] +":\n" +
                            (args.Bot.Commands.ContainsKey(args.Args[0])?
                                args.Bot.Commands[args.Args[0]].HelpText :
                                "Command not found")
                        );
                    }
                }
            );

            CommandsList["h"] = CommandsList["help"];

            CommandsList["rot13"] = new BotCommand(
                "Performs rot13 encryption.\nUsage: rot13 <sentence>",
                args => {
                    var argText = args.Args.Aggregate((t, i) => t + " " + i);
                    var output = string.Concat(argText.Select(x => (x >= 'a' && x <= 'z') ? (char)((x - 'a' + 13) % 26 + 'a') :
                    ((x >= 'A' && x <= 'Z') ? (char)((x - 'A' + 13) % 26 + 'A') : x)));
                    args.Bot.Client.SendChat(output);
                }
            );
        }
Exemple #2
0
 public void AddCommand(string name, BotCommand command)
 {
     Commands[name] = command;
 }