added func to search based on best criteria
This commit is contained in:
14
bunnybot.go
14
bunnybot.go
@@ -68,12 +68,24 @@ func message_create (s *discordgo.Session, m *discordgo.MessageCreate) {
|
|||||||
// awwnime (test)
|
// awwnime (test)
|
||||||
if message == "awwnime" {
|
if message == "awwnime" {
|
||||||
// get url
|
// get url
|
||||||
url := <-get_subreddit_image("awwnime")
|
url := <-get_image("awwnime")
|
||||||
|
|
||||||
// print message with url
|
// print message with url
|
||||||
s.ChannelMessageSend(m.ChannelID, url)
|
s.ChannelMessageSend(m.ChannelID, url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// other image test
|
||||||
|
if message == "self" {
|
||||||
|
// get url
|
||||||
|
url := <-get_image("self")
|
||||||
|
|
||||||
|
if(len(url) > 0) {
|
||||||
|
s.ChannelMessageSend(m.ChannelID, url)
|
||||||
|
} else {
|
||||||
|
s.ChannelMessageSend(m.ChannelID, "No images found, please try again")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//get_redditbooru("awwnime")
|
//get_redditbooru("awwnime")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
37
images.go
37
images.go
@@ -85,6 +85,41 @@ func build_redditbooru_sources() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// search based on the most appropriate location
|
||||||
|
func get_image(sub string) <-chan string {
|
||||||
|
// make the channell
|
||||||
|
ret := make(chan string)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(ret)
|
||||||
|
|
||||||
|
// setup variable
|
||||||
|
var image string
|
||||||
|
var found bool = false
|
||||||
|
|
||||||
|
// check to see if it is in the redditbooru sources
|
||||||
|
for _,title := range redditbooru_sources {
|
||||||
|
if title == sub {
|
||||||
|
image = <-get_redditbooru_image(sub)
|
||||||
|
found = true
|
||||||
|
ret <- image
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if not in redditbooru, check reddit
|
||||||
|
if found == false {
|
||||||
|
image = <-get_subreddit_image(sub)
|
||||||
|
ret <- image
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}()
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// redditbooru request
|
// redditbooru request
|
||||||
func get_redditbooru_image(sub string) <-chan string{
|
func get_redditbooru_image(sub string) <-chan string{
|
||||||
// make the channel
|
// make the channel
|
||||||
@@ -124,7 +159,7 @@ func get_redditbooru_image(sub string) <-chan string{
|
|||||||
|
|
||||||
// set the return value
|
// set the return value
|
||||||
ret <- img_url
|
ret <- img_url
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user