func Register(bot *irc.IRC) { defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Urban Dictionary plugin")) events.CmdListen(&events.CmdListener{ Commands: []string{"urbandictionary", "ud"}, Help: "Looks up Urban Dictionary entries. NSFW", Syntax: bot.Config.Prefix + "ud <term> - Example: " + bot.Config.Prefix + "ud scrobble", Callback: func(input *events.Params) { uri := fmt.Sprintf("http://api.urbandictionary.com/v0/define?term=%s", url.QueryEscape(input.Data)) body, err := web.Get(&uri) if err != "" { bot.Say(input.Context, err) return } ud := &UDResponse{} jserr := json.Unmarshal(body, &ud) if jserr != nil { logger.Error("Couldn't parse UD's JSON: " + jserr.Error()) return } if ud.Result == "no_results" { bot.Say(input.Context, fmt.Sprintf("\"%s\" is not a thing on Urban Dictionary.", input.Data)) return } var resp string = "" var max int = 3 if len(ud.List) < max { max = len(ud.List) } for i := 0; i < max; i++ { resp += fmt.Sprintf("%d) %s, ", i+1, ud.List[i].Definition) } bot.Say(input.Context, ud.List[0].Word+" ~ "+lib.SingleSpace(resp[0:len(resp)-2])) }}) }
func Register(bot *irc.IRC) { defer logger.Info(lib.TimeTrack(time.Now(), "Loading the YouTube plugin")) events.CmdListen(&events.CmdListener{ Commands: []string{"youtube", "yt"}, Help: "YouTubes stuff.", Syntax: bot.Config.Prefix + "yt <search terms> - Example: " + bot.Config.Prefix + "yt we like big booty bitches", Callback: func(input *events.Params) { ytr := &YouTubeResults{} uri := fmt.Sprintf("http://gdata.youtube.com/feeds/api/videos?q=%s&max-results=1&v=2&alt=json", url.QueryEscape(input.Data)) body, err := web.Get(&uri) if err != "" { logger.Error("YouTube Failed: " + err) bot.Say(input.Context, "Woops.") return } errr := json.Unmarshal(body, &ytr) if errr != nil { logger.Error("Couldn't parse youtube's JSON:" + errr.Error()) bot.Say(input.Context, "Herp. Check logs") return } if len(ytr.Feed.Entry) == 0 { bot.Say(input.Context, fmt.Sprintf("\"%s\" is not a thing on YouTube.", input.Data)) return } yt := &ytr.Feed.Entry[0] duration, errr := time.ParseDuration(yt.Info.Duration["seconds"] + "s") resp := fmt.Sprintf("%s ~ [%s] %s - %s views ~ http://youtu.be/%s ~ %s", *yt.Title["$t"], &duration, yt.Info.Date["$t"][0:10], lib.CommaNum(yt.Stats["viewCount"]), yt.Info.ID["$t"], yt.Info.Description["$t"]) bot.Say(input.Context, resp) resp = "" ytr = nil }}) }
func checkUpdates(bot *irc.IRC, source string, context string) { var manga Manga var uri, message string var watched map[string]MangaEntry loadWatched(&manga) switch source { case "mangafox": uri = "http://mangafox.me/rss/latest_manga_chapters.xml" watched = manga.MangaFox case "mangastream": uri = "http://mangastream.com/rss" watched = manga.MangaStream } data, err := web.Get(&uri) if err != "" { logger.Error(err) return } var entries map[string]MangaEntry entries, perr := parseRSS(data, source) if perr != nil { logger.Error(perr.Error()) return } keys := getKeys(source) updates := make([]irc.RatedMessage, 0) var method string var newEntry MangaEntry for title, entry := range entries { for _, key := range keys { if strings.Index(title, key) > -1 { if entry.Date > watched[key].Date { // update found switch source { case "mangastream": message = fmt.Sprintf("%s is out! \\o/ ~ %s ~ %q", entry.Title, entry.Link, entry.Desc) newEntry = MangaEntry{ Manga: entry.Title[:len(key)], Title: entry.Title, Date: entry.Date, Desc: entry.Desc, Link: entry.Link, Announce: watched[key].Announce, } case "mangafox": message = fmt.Sprintf("%s is out! \\o/ ~ %s", entry.Title, entry.Link) newEntry = MangaEntry{ Manga: entry.Title[:len(key)], Title: entry.Title, Date: entry.Date, Link: entry.Link, Announce: watched[key].Announce, } } delete(watched, key) watched[key] = newEntry if context != "" && !lib.HasElementString(watched[key].Announce, context) { if context[0:1] == "#" { method = "say" } else { method = "notice" } updates = append(updates, irc.RatedMessage{ Method: method, Target: context, Message: message, }) } for _, target := range watched[key].Announce { if target[0:1] == "#" { method = "say" } else { method = "notice" } updates = append(updates, irc.RatedMessage{ Method: method, Target: target, Message: message, }) } } } } } if len(updates) > 0 { bot.Rated(&updates) saveWatched(&manga) } else if context != "" { bot.Say(context, "Nothing new. :\\") } }