2015-11-19 17:47:47 +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 (
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/arachnist/gorepost/irc"
|
|
|
|
)
|
|
|
|
|
2015-11-20 08:53:54 +00:00
|
|
|
var errNotReally = errors.New("not an error")
|
2015-11-19 17:47:47 +00:00
|
|
|
|
|
|
|
func redirectError(*http.Request, []*http.Request) error {
|
2015-11-20 08:53:54 +00:00
|
|
|
return errNotReally
|
2015-11-19 17:47:47 +00:00
|
|
|
}
|
|
|
|
|
2015-11-29 14:50:31 +00:00
|
|
|
func kotki(output func(irc.Message), msg irc.Message) {
|
2015-11-19 17:47:47 +00:00
|
|
|
if strings.Split(msg.Trailing, " ")[0] != ":kotki" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var rmsg string
|
|
|
|
tr := &http.Transport{
|
|
|
|
TLSHandshakeTimeout: 5 * time.Second,
|
|
|
|
ResponseHeaderTimeout: 5 * time.Second,
|
|
|
|
}
|
|
|
|
client := &http.Client{
|
|
|
|
Transport: tr,
|
|
|
|
CheckRedirect: redirectError,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, _ := client.Get("http://thecatapi.com/api/images/get?format=src&type=png")
|
|
|
|
rurl, _ := resp.Location()
|
|
|
|
rmsg = rurl.String()
|
|
|
|
|
2015-11-29 14:50:31 +00:00
|
|
|
output(reply(msg, rmsg))
|
2015-11-19 17:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
addCallback("PRIVMSG", "kotki", kotki)
|
|
|
|
}
|