Merge pull request #22 from xddxdd/lantian-dev
frontend: add generic whois shorten mode
This commit is contained in:
commit
80e66a7a81
@ -49,3 +49,33 @@ func dn42WhoisFilter(whois string) string {
|
||||
return commandResult
|
||||
}
|
||||
}
|
||||
|
||||
/* experimental, behavior may change */
|
||||
func shortenWhoisFilter(whois string) string {
|
||||
commandResult := ""
|
||||
skippedLines := 0
|
||||
|
||||
for _, s := range strings.Split(whois, "\n") {
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
shouldSkip := false
|
||||
shouldSkip = shouldSkip || len(s) == 0
|
||||
shouldSkip = shouldSkip || len(s) > 80
|
||||
shouldSkip = shouldSkip || len(s) > 0 && s[0] == '#'
|
||||
shouldSkip = shouldSkip || !strings.Contains(s, ":")
|
||||
shouldSkip = shouldSkip || strings.Index(s, ":") > 20
|
||||
|
||||
if shouldSkip {
|
||||
skippedLines++
|
||||
continue
|
||||
}
|
||||
|
||||
commandResult += s + "\n"
|
||||
}
|
||||
|
||||
if skippedLines > 0 {
|
||||
return commandResult + fmt.Sprintf("\n%d line(s) skipped.\n", skippedLines)
|
||||
} else {
|
||||
return commandResult
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
|
||||
} else if telegramIsCommand(request.Message.Text, "whois") {
|
||||
if setting.netSpecificMode == "dn42" {
|
||||
if setting.netSpecificMode == "dn42" || setting.netSpecificMode == "dn42_generic" {
|
||||
targetNumber, err := strconv.ParseUint(target, 10, 64)
|
||||
if err == nil {
|
||||
if targetNumber < 10000 {
|
||||
@ -119,6 +119,8 @@ func webHandlerTelegramBot(w http.ResponseWriter, r *http.Request) {
|
||||
tempResult := whois(target)
|
||||
if setting.netSpecificMode == "dn42" {
|
||||
commandResult = dn42WhoisFilter(tempResult)
|
||||
} else if setting.netSpecificMode == "dn42_shorten" || setting.netSpecificMode == "shorten" {
|
||||
commandResult = shortenWhoisFilter(tempResult)
|
||||
} else {
|
||||
commandResult = tempResult
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user