From 5157f64f9dadbe1080bae8737ca4c55220e81ab9 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Wed, 8 Apr 2020 14:58:25 +0800 Subject: [PATCH] Add whois result filter (for DN42) --- frontend/telegram_bot.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/telegram_bot.go b/frontend/telegram_bot.go index a6bc32e..b677c45 100644 --- a/frontend/telegram_bot.go +++ b/frontend/telegram_bot.go @@ -93,7 +93,30 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) { } } else if telegramIsCommand(request.Message.Text, "whois") { - commandResult = whois(target) + tempResult := whois(target) + + // Filter out some long (and useless) keys + filteredPrefix := []string{ + "descr:", "remarks:", "ds-rdata:", "auth:", "country:", + "nserver:", "status:", "pgp-fingerprint:", "mp-import:", "mp-export:", + "members:", "key:", "inetnum:", "inet6num:", "%", + } + for _, s := range strings.Split(tempResult, "\n") { + if len(s) == 0 { + continue + } + shouldSkip := false + for _, filtered := range filteredPrefix { + if strings.HasPrefix(s, filtered) { + shouldSkip = true + } + } + if shouldSkip { + continue + } + + commandResult += s + "\n" + } } else if telegramIsCommand(request.Message.Text, "help") { commandResult = `