Add our own botlist for user-agent matching. Closes #51

This commit is contained in:
Gabe Kangas
2020-07-13 19:07:30 -07:00
parent 46b3922e1d
commit ab21706d73
3 changed files with 40 additions and 4 deletions

View File

@@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/mssola/user_agent"
)
//GetTemporaryPipePath gets the temporary path for the streampipe.flv file
@@ -41,3 +43,24 @@ func Copy(source, destination string) error {
return ioutil.WriteFile(destination, input, 0644)
}
// IsUserAgentABot returns if a web client user-agent is seen as a bot
func IsUserAgentABot(userAgent string) bool {
if userAgent == "" {
return false
}
botStrings := []string{
"mastodon",
"pleroma",
}
for _, botString := range botStrings {
if strings.Contains(strings.ToLower(userAgent), botString) {
return true
}
}
ua := user_agent.New(userAgent)
return ua.Bot()
}