當前位置: 首頁>>代碼示例>>Golang>>正文


Golang IRC.Rated方法代碼示例

本文整理匯總了Golang中Kari/irc.IRC.Rated方法的典型用法代碼示例。如果您正苦於以下問題:Golang IRC.Rated方法的具體用法?Golang IRC.Rated怎麽用?Golang IRC.Rated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Kari/irc.IRC的用法示例。


在下文中一共展示了IRC.Rated方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkUpdates

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. :\\")
	}
}
開發者ID:Kaioshi,項目名稱:Kari,代碼行數:94,代碼來源:manga.go


注:本文中的Kari/irc.IRC.Rated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。