func newMessage(session *discordgo.Session, message *discordgo.MessageCreate) {
	if message.Author.ID == session.State.User.ID {
		return
	}

	formattedMessage := strings.Join(strings.Fields(message.Content), "%20")

	if strings.HasPrefix(formattedMessage, "_anime") {

		name := strings.TrimPrefix(formattedMessage, "_anime")

		response, err := http.Get("https://kitsu.io/api/edge/anime?filter[text]={" + name + "}&page[limit]=1") //TODO Sort by popular
		if err != nil || response.Status != "200 OK" {
			fmt.Println("Request failed (Status : "+ response.Status + "). Cannot get anime.\n", err)
			return
		}
		defer response.Body.Close()

		body, err := ioutil.ReadAll(response.Body)
		if err != nil {
			fmt.Println("Error while reading request body,", err)
			return
		}

		var anime Anime
		parseAnimeInfos(body, &anime)

		if len(anime.Data) < 0 {
			fmt.Println("Didn't find any related anime with given name")
		} else {
			createAndSendEmbedMessage(session, message.ChannelID, anime.Data[0])
		}
	}
}
/**
	Callback called whenever a new message is posted on a channel
 */
Callback called whenever a new message is posted on a channel
/ ** Callback called whenever a new message is posted on a channel * /
func newMessage(session *discordgo.Session, message *discordgo.MessageCreate) {
	if message.Author.ID == session.State.User.ID {
		return
	}
	formattedMessage := strings.Join(strings.Fields(message.Content), "%20")
	if strings.HasPrefix(formattedMessage, "_anime") {
		name := strings.TrimPrefix(formattedMessage, "_anime")
		response, err := http.Get("https://kitsu.io/api/edge/anime?filter[text]={" + name + "}&page[limit]=1") 
		if err != nil || response.Status != "200 OK" {
			fmt.Println("Request failed (Status : "+ response.Status + "). Cannot get anime.\n", err)
			return
		}
		defer response.Body.Close()
		body, err := ioutil.ReadAll(response.Body)
		if err != nil {
			fmt.Println("Error while reading request body,", err)
			return
		}
		var anime Anime
		parseAnimeInfos(body, &anime)
		if len(anime.Data) < 0 {
			fmt.Println("Didn't find any related anime with given name")
		} else {
			createAndSendEmbedMessage(session, message.ChannelID, anime.Data[0])
		}
	}
}
func newMessage ( session * discordgo . Session , message * discordgo . MessageCreate ) { if message . Author . ID == session . State . User . ID { return } formattedMessage := strings . Join ( strings . Fields ( message . Content ) , " " ) if strings . HasPrefix ( formattedMessage , " " ) { name := strings . TrimPrefix ( formattedMessage , " " ) response , err := http . Get ( " " + name + " " ) if err != nil || response . Status != " " { fmt . Println ( " " + response . Status + " \n " , err ) return } defer response . Body . Close ( ) body , err := ioutil . ReadAll ( response . Body ) if err != nil { fmt . Println ( " " , err ) return } var anime Anime parseAnimeInfos ( body , & anime ) if len ( anime . Data ) < 0 { fmt . Println ( " " ) } else { createAndSendEmbedMessage ( session , message . ChannelID , anime . Data [ 0 ] ) } } }
Callback called whenever a new message is posted on a channel
Callback called whenever a new message is posted on a channel
//TODO Sort by popular