gorepost/bot/bonjour.go

39 lines
798 B
Go
Raw Normal View History

2015-12-09 14:47:59 +00:00
// +build bonjourmadame
//
2015-11-19 15:12:24 +00:00
// Copyright 2015 Robert S. Gerus. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package bot
import (
"fmt"
"math/rand"
"strings"
"time"
"github.com/arachnist/gorepost/irc"
)
2015-11-29 16:46:29 +00:00
func bonjour(output func(irc.Message), msg irc.Message) {
2015-11-19 15:12:24 +00:00
var rmsg string
if strings.Split(msg.Trailing, " ")[0] != ":bonjour" {
return
}
2015-11-21 11:51:43 +00:00
img, err := httpGetXpath("http://www.bonjourmadame.fr/page/"+fmt.Sprintf("%d", rand.Intn(2370)+1), "//div[@class='photo post']//img/@src")
2015-11-19 15:12:24 +00:00
if err != nil {
rmsg = fmt.Sprint("error:", err)
} else {
rmsg = "bonjour (nsfw): " + img
}
2015-11-29 16:46:29 +00:00
output(reply(msg, rmsg))
2015-11-19 15:12:24 +00:00
}
func init() {
rand.Seed(time.Now().UnixNano())
addCallback("PRIVMSG", "bonjour", bonjour)
}