コード例 #1
0
ファイル: Get.cs プロジェクト: Baggykiin/BaggyBot-2
        public override void Use(CommandArgs command)
        {
            var cmdParser = new CommandParser(new Operation())
                .AddOperation("cfg", new Operation()
                    .AddArgument("config-key", string.Empty))
                .AddOperation("uid", new Operation()
                    .AddArgument("user", command.Sender.Nick))
                .AddOperation("users", new Operation()
                    .AddArgument("channel", command.Channel));

            OperationResult result;
            try
            {
                result = cmdParser.Parse(command.FullArgument);
            }
            catch (InvalidCommandException e)
            {
                command.ReturnMessage(e.Message);
                return;
            }

            switch (result.OperationName)
            {
                case "default":
                    InformUsage(command);
                    break;
                case "cfg":
                    if (!UserTools.Validate(command.Sender))
                    {
                        command.Reply(Messages.CmdNotAuthorised);
                        return;
                    }
                    var key = result.Arguments["config-key"];
                    var value = MiscTools.GetDynamic(key.Split('.').Select(k => k.ToPascalCase()).ToArray(), ConfigManager.Config);
                    command.Reply($"{(string.IsNullOrEmpty(key)? "config" : "config." + key)} = {value}");
                    break;
                case "uid":
                    var uid = command.Client.StatsDatabase.GetIdFromNick(result.Arguments["user"]);
                    if (uid == -2)
                        command.Reply($"I don't know a user with {result.Arguments["user"]} as their primary name");
                    else
                        command.Reply($"the user Id belonging to {result.Arguments["user"]} is {uid}");
                    break;
                case "users":
                    var channel = result.Arguments["channel"];

                    if (command.Client.InChannel(channel))
                    {
                        var ircChannel = command.Client.GetChannel(channel);
                        command.Reply($"users in {channel}: {string.Join(", ", ircChannel.UserCount)}");
                    }
                    else
                    {
                        command.Reply("I'm not in that channel.");
                    }
                    break;
            }
        }
コード例 #2
0
ファイル: Search.cs プロジェクト: Baggykiin/BaggyBot-2
        public override void Use(CommandArgs command)
        {
            if(command.FullArgument == null)
            {
                InformUsage(command);
                return;
            }

            var parser = new CommandParser(new Operation().AddKey("max-results", "1", 'n').AddRestArgument());

            var result = parser.Parse(command.FullArgument);
            var numDisplayed = int.Parse(result.Keys["max-results"]);
            if (numDisplayed > 3 && !UserTools.Validate(command.Sender))
            {
                command.Reply("only bot operators may request more than three results.");
                return;
            }
            var query = result.RestArgument;

            var matches = command.Client.StatsDatabase.FindLine(query);
            switch (matches.Count)
            {
                case 0:
                    command.Reply("no matches found.");
                    break;
                case 1:
                    command.Reply("1 match found: " + matches[0]);
                    break;
                default:
                    if (numDisplayed == 1)
                        command.Reply($"{matches.Count} matches (1 displayed): {matches[0]}");
                    else
                    {
                        int matchNumber = 0;
                        foreach (var match in matches.Take(numDisplayed))
                        {
                            command.Reply($"match {++matchNumber} of {numDisplayed}: {match}");
                        }
                    }
                    break;
            }
        }
コード例 #3
0
ファイル: Resolve.cs プロジェクト: Baggykiin/BaggyBot-2
 public override void Use(CommandArgs command)
 {
     var parser = new CommandParser(new Operation().AddArgument("hostname", null));
     OperationResult result;
     try
     {
         result = parser.Parse(command.FullArgument);
     }
     catch (InvalidCommandException e)
     {
         command.ReturnMessage(e.Message);
         return;
     }
     if (result.Arguments["hostname"] == null)
     {
         command.Reply("Usage: -resolve <hostname>");
     }
     else
     {
         ResolveHost(result.Arguments["hostname"], command);
     }
 }