some golint/vet and changed output format.

feedback in #exmormon said put url at end.
This commit is contained in:
Stephen McQuay 2016-05-08 13:17:03 -07:00
parent 4055810f22
commit 2547281d09
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D
2 changed files with 27 additions and 25 deletions

View File

@ -11,8 +11,8 @@ import (
irc "github.com/fluffle/goirc/client"
)
var host *string = flag.String("host", "localhost:6668", "irc server hostname")
var channel *string = flag.String("channel", "#exmormon", "irc channel")
var host = flag.String("host", "localhost:6668", "irc server hostname")
var channel = flag.String("channel", "#exmormon", "irc channel")
func main() {
rand.Seed(time.Now().UnixNano())
@ -21,17 +21,19 @@ func main() {
done := make(chan bool)
Register(*host, *channel, done)
register(*host, *channel, done)
<-done
}
const name = "BYbot"
// BY is the Go embodiment of Brigham Young.
type BY struct {
quotes []string
poke chan bool
}
// Random returns a random BY quote. That asshat.
func (by *BY) Random() string {
if len(by.quotes) == 0 {
return ""
@ -52,7 +54,7 @@ func (by *BY) spew(conn *irc.Conn, channel string) {
}
}
func Register(host, channel string, done chan<- bool) {
func register(host, channel string, done chan<- bool) {
var p *regexp.Regexp
by := BY{
quotes,
@ -95,7 +97,7 @@ func Register(host, channel string, done chan<- bool) {
}
}
var quotes []string = []string{
var quotes = []string{
"♬♬ God changed his mind about black people (black people!!) ♬♬",
"Wife! Bring me a wife!!",

View File

@ -13,9 +13,9 @@ import (
irc "github.com/fluffle/goirc/client"
)
var host *string = flag.String("host", "localhost:6668", "irc server hostname")
var channel *string = flag.String("channel", "#exmormon", "irc channel")
var top *int = flag.Int("top", 5, "number of top posts to use")
var host = flag.String("host", "localhost:6668", "irc server hostname")
var channel = flag.String("channel", "#exmormon", "irc channel")
var top = flag.Int("top", 5, "number of top posts to use")
func main() {
rand.Seed(time.Now().UnixNano())
@ -24,13 +24,13 @@ func main() {
done := make(chan bool)
Register(*host, *channel, done)
register(*host, *channel, done)
<-done
}
const name = "reddit"
const name = "reddit-exmo"
func Register(host, channel string, done chan<- bool) {
func register(host, channel string, done chan<- bool) {
var p *regexp.Regexp
c := irc.SimpleClient(name, name)
@ -68,8 +68,8 @@ func Register(host, channel string, done chan<- bool) {
if err != nil {
log.Printf("%+v", err)
}
for _, item := range prime {
seen[item.ID] = item.Score
for _, i := range prime {
seen[i.ID] = i.Score
}
for {
@ -77,13 +77,13 @@ func Register(host, channel string, done chan<- bool) {
if err != nil {
log.Printf("%+v", err)
}
for _, item := range latest {
if _, ok := seen[item.ID]; ok {
for _, i := range latest {
if _, ok := seen[i.ID]; ok {
continue
}
log.Printf("decided to talk about this: %+v", item)
seen[item.ID] = item.Score
c.Privmsgf(channel, "%v", item)
log.Printf("decided to talk about this: %+v", i)
seen[i.ID] = i.Score
c.Privmsgf(channel, "%v", i)
}
time.Sleep(5 * time.Minute)
}
@ -94,7 +94,7 @@ func Register(host, channel string, done chan<- bool) {
}
}
type Item struct {
type item struct {
ID string `json:"id"`
Author string `json:"author"`
Score int `json:"score"`
@ -103,7 +103,7 @@ type Item struct {
Comments int `json:"num_comments"`
}
func (i Item) String() string {
func (i item) String() string {
com := ""
switch i.Comments {
@ -114,19 +114,19 @@ func (i Item) String() string {
default:
com = fmt.Sprintf(" (%d comments)", i.Comments)
}
return fmt.Sprintf("https://redd.it/%s : %s %v", i.ID, i.Title, com)
url := fmt.Sprintf("https://redd.it/%s", i.ID)
return fmt.Sprintf("%s %v (current score: %d) %s", i.Title, com, i.Score, url)
}
type response struct {
Data struct {
Children []struct {
Data Item
Data item
}
}
}
func items() ([]Item, error) {
func items() ([]item, error) {
url := fmt.Sprintf("https://www.reddit.com/r/exmormon.json")
client := http.Client{}
req, err := http.NewRequest("GET", url, nil)
@ -145,7 +145,7 @@ func items() ([]Item, error) {
}
defer resp.Body.Close()
items := []Item{}
items := []item{}
for _, child := range rresp.Data.Children {
items = append(items, child.Data)
}