Update log levels, add safe search toggle

main
Astra 2022-10-14 23:33:34 +00:00
parent a3060fe3ad
commit 2035967c0e
1 changed files with 10 additions and 3 deletions

13
main.go
View File

@ -53,7 +53,7 @@ type Params struct {
func main() {
logger.Layout = time.Stamp
logger.BitwiseLevel = logger.LogEverything
logger.BitwiseLevel = logger.LogInfo | logger.LogWarning | logger.LogCritical
bot, err := tgbotapi.NewBotAPI(os.Getenv("BOT_TOKEN"))
if err != nil {
logger.Critical(err.Error())
@ -71,7 +71,7 @@ func main() {
for update := range updates {
if update.InlineQuery != nil {
if update.InlineQuery.Query != "" {
logger.Info("Inline query %q from %s", update.InlineQuery.Query, update.InlineQuery.From)
logger.Debug("Inline query %q from %s", update.InlineQuery.Query, update.InlineQuery.From)
var results []interface{}
images := getImageList(update.InlineQuery.Query)
@ -100,6 +100,13 @@ func main() {
}
func getImageList(query string) []Results {
safeSearch := "-1" // -1 = safe off, 1 = safe on
if len(query) >= 8 {
if strings.HasPrefix(query, "safe:on") {
safeSearch = "1"
query = query[8:]
}
}
params := &Params{Query: query}
s := sling.New().Get(ddgURL)
s.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36")
@ -132,7 +139,7 @@ func getImageList(query string) []Results {
Q: query,
VQD: token,
F: ",,,,,",
P: "-1",
P: safeSearch,
S: "0",
U: "bing",
}