some golint/vet and changed output format.
feedback in #exmormon said put url at end.
This commit is contained in:
parent
4055810f22
commit
2547281d09
@ -11,8 +11,8 @@ import (
|
|||||||
irc "github.com/fluffle/goirc/client"
|
irc "github.com/fluffle/goirc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var host *string = flag.String("host", "localhost:6668", "irc server hostname")
|
var host = flag.String("host", "localhost:6668", "irc server hostname")
|
||||||
var channel *string = flag.String("channel", "#exmormon", "irc channel")
|
var channel = flag.String("channel", "#exmormon", "irc channel")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
@ -21,17 +21,19 @@ func main() {
|
|||||||
|
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
Register(*host, *channel, done)
|
register(*host, *channel, done)
|
||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = "BYbot"
|
const name = "BYbot"
|
||||||
|
|
||||||
|
// BY is the Go embodiment of Brigham Young.
|
||||||
type BY struct {
|
type BY struct {
|
||||||
quotes []string
|
quotes []string
|
||||||
poke chan bool
|
poke chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Random returns a random BY quote. That asshat.
|
||||||
func (by *BY) Random() string {
|
func (by *BY) Random() string {
|
||||||
if len(by.quotes) == 0 {
|
if len(by.quotes) == 0 {
|
||||||
return ""
|
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
|
var p *regexp.Regexp
|
||||||
by := BY{
|
by := BY{
|
||||||
quotes,
|
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!!) ♬♬",
|
"♬♬ God changed his mind about black people (black people!!) ♬♬",
|
||||||
|
|
||||||
"Wife! Bring me a wife!!",
|
"Wife! Bring me a wife!!",
|
||||||
|
@ -13,9 +13,9 @@ import (
|
|||||||
irc "github.com/fluffle/goirc/client"
|
irc "github.com/fluffle/goirc/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
var host *string = flag.String("host", "localhost:6668", "irc server hostname")
|
var host = flag.String("host", "localhost:6668", "irc server hostname")
|
||||||
var channel *string = flag.String("channel", "#exmormon", "irc channel")
|
var channel = flag.String("channel", "#exmormon", "irc channel")
|
||||||
var top *int = flag.Int("top", 5, "number of top posts to use")
|
var top = flag.Int("top", 5, "number of top posts to use")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
@ -24,13 +24,13 @@ func main() {
|
|||||||
|
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
|
|
||||||
Register(*host, *channel, done)
|
register(*host, *channel, done)
|
||||||
<-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
|
var p *regexp.Regexp
|
||||||
|
|
||||||
c := irc.SimpleClient(name, name)
|
c := irc.SimpleClient(name, name)
|
||||||
@ -68,8 +68,8 @@ func Register(host, channel string, done chan<- bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
}
|
}
|
||||||
for _, item := range prime {
|
for _, i := range prime {
|
||||||
seen[item.ID] = item.Score
|
seen[i.ID] = i.Score
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -77,13 +77,13 @@ func Register(host, channel string, done chan<- bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%+v", err)
|
log.Printf("%+v", err)
|
||||||
}
|
}
|
||||||
for _, item := range latest {
|
for _, i := range latest {
|
||||||
if _, ok := seen[item.ID]; ok {
|
if _, ok := seen[i.ID]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("decided to talk about this: %+v", item)
|
log.Printf("decided to talk about this: %+v", i)
|
||||||
seen[item.ID] = item.Score
|
seen[i.ID] = i.Score
|
||||||
c.Privmsgf(channel, "%v", item)
|
c.Privmsgf(channel, "%v", i)
|
||||||
}
|
}
|
||||||
time.Sleep(5 * time.Minute)
|
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"`
|
ID string `json:"id"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Score int `json:"score"`
|
Score int `json:"score"`
|
||||||
@ -103,7 +103,7 @@ type Item struct {
|
|||||||
Comments int `json:"num_comments"`
|
Comments int `json:"num_comments"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Item) String() string {
|
func (i item) String() string {
|
||||||
com := ""
|
com := ""
|
||||||
|
|
||||||
switch i.Comments {
|
switch i.Comments {
|
||||||
@ -114,19 +114,19 @@ func (i Item) String() string {
|
|||||||
default:
|
default:
|
||||||
com = fmt.Sprintf(" (%d comments)", i.Comments)
|
com = fmt.Sprintf(" (%d comments)", i.Comments)
|
||||||
}
|
}
|
||||||
|
url := fmt.Sprintf("https://redd.it/%s", i.ID)
|
||||||
return fmt.Sprintf("https://redd.it/%s : %s %v", i.ID, i.Title, com)
|
return fmt.Sprintf("%s %v (current score: %d) %s", i.Title, com, i.Score, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
type response struct {
|
type response struct {
|
||||||
Data struct {
|
Data struct {
|
||||||
Children []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")
|
url := fmt.Sprintf("https://www.reddit.com/r/exmormon.json")
|
||||||
client := http.Client{}
|
client := http.Client{}
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
@ -145,7 +145,7 @@ func items() ([]Item, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
items := []Item{}
|
items := []item{}
|
||||||
for _, child := range rresp.Data.Children {
|
for _, child := range rresp.Data.Children {
|
||||||
items = append(items, child.Data)
|
items = append(items, child.Data)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user