Beispiel #1
0
 public DnsMiddleware(IMiddleware next, DnsPlugin dnsPlugin, ILog log)
     : base(next)
 {
     this.dnsPlugin       = dnsPlugin;
     this.log             = log;
     this.HandlerMappings = new[]
     {
         new HandlerMapping
         {
             ValidHandles  = StartsWithHandle.For($"{Configuration.CommandPrefix} {Lookup}"),
             EvaluatorFunc = this.DnsLookupHandler,
             Description   = $"Gets IP address for dns entry. {GetHelpText(Lookup)}",
             VisibleInHelp = true
         },
     };
 }
Beispiel #2
0
        private IEnumerable <ResponseMessage> DnsLookupHandler(IncomingMessage incomingMessage, IValidHandle matchedHandle)
        {
            yield return(incomingMessage.IndicateTypingOnChannel());

            if (!DnsLookupCommandWellFormatted(incomingMessage.TargetedText))
            {
                yield return(incomingMessage.ReplyToChannel($"Command was not formatted correctly. Help: {GetHelpText(Lookup)}"));

                yield break;
            }

            var hostToLookup = DnsPlugin.GetHostFromMessage(incomingMessage.TargetedText);
            var ipAddresses  = DnsPlugin.LookUpIpFromCommandText(hostToLookup);

            if (ipAddresses == null)
            {
                yield return(incomingMessage.ReplyToChannel($"Error looking up requested host '{hostToLookup}'. No result were returned."));

                yield break;
            }

            yield return(incomingMessage.ReplyToChannel($"dns lookup for '{hostToLookup}' returned: {DnsPlugin.GetIpAddressesAsText(ipAddresses)}"));
        }