Exemple #1
0
        public override BotMessage GetResponse(MessageContext context)
        {
            var runner = FileRunners.Scripts.Find(context.CleanMessage());

            if (runner == null)
            {
                return new BotMessage()
                       {
                           Text = "Command not found."
                       }
            }
            ;
            Log.Information($"Start executing {runner.Command}");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var enumerable = runner.Execute(context);

            foreach (var text in enumerable)
            {
                context.Say(text);
            }

            stopwatch.Stop();
            Log.Information($"Done executing {runner.Command} in {stopwatch.Elapsed}");
            return(new BotMessage()
            {
                Text = "Done."
            });
        }
Exemple #2
0
        public override BotMessage GetResponse(MessageContext context)
        {
            var hasSimilar = FileRunners.Scripts.FindWithSimilarNames(context.CleanMessage()).ToArray();

            if (hasSimilar.Any())
            {
                var stringJoinAnd = hasSimilar
                                    .Select(x => $"*{x}*")
                                    .StringJoinAnd(" or ");
                return(new BotMessage()
                {
                    Text = $"Could not find command `{context.CleanMessage()}`. Did you mean to run {stringJoinAnd}."
                });
            }
            return(new BotMessage()
            {
                Text = "Sorry I don't know that command. Type *help* for command information."
            });
        }
        public override BotMessage GetResponse(MessageContext context)
        {
            FileRunner runner = null;

            foreach (FileRunner fileRunner in FileRunners.Scripts.Where(x => x.MatchesString(context.CleanMessage())))
            {
                runner = fileRunner;
                break;
            }
            if (runner != null)
            {
                var enumerable = runner.Execute(context);
                foreach (var text in enumerable)
                {
                    context.Say(text);
                }
                return(new BotMessage()
                {
                    Text = "Done."
                });
            }
            return(new BotMessage()
            {
                Text = "Command not found."
            });
        }
 public override bool CanRespond(MessageContext context)
 {
     return(base.CanRespond(context) && FileRunners.Scripts.Any(x => x.MatchesString(context.CleanMessage())));
 }
Exemple #5
0
 public override bool CanRespond(MessageContext context)
 {
     return(base.CanRespond(context) && FileRunners.Scripts.Find(context.CleanMessage()) != null);
 }