当前位置: 首页>>代码示例>>Golang>>正文


Golang irc.IRC类代码示例

本文整理汇总了Golang中Kari/irc.IRC的典型用法代码示例。如果您正苦于以下问题:Golang IRC类的具体用法?Golang IRC怎么用?Golang IRC使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IRC类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the TitleSnarfer plugin"))

	events.EvListenComplex(&events.ComplexEventListener{
		Handle: "titlesnarfer",
		Event:  "PRIVMSG",
		Regex:  "(https?:\\/\\/[^\001 ]+)",
		Callback: func(input *events.Params) {
			if input.Command == "" {
				bot.Say(input.Context, web.GetTitle(input.Match))
			}
		}})
}
开发者ID:Kaioshi,项目名称:Kari,代码行数:13,代码来源:titlesnarfer.go

示例2: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Google plugin"))

	events.CmdListen(&events.CmdListener{
		Commands: []string{"google", "g"},
		Help:     "Googles stuff~",
		Syntax:   bot.Config.Prefix + "g <search terms>",
		Callback: func(input *events.Params) {
			g := web.Google(input.Data, 1)
			if g.Error != "" {
				bot.Say(input.Context, g.Error)
				return
			}
			bot.Say(input.Context, fmt.Sprintf("%s ~ %s ~ %s",
				g.Results.Data[0].Title, g.Results.Data[0].URL,
				lib.StripHtml(g.Results.Data[0].Content)))
		}})
}
开发者ID:Kaioshi,项目名称:Kari,代码行数:18,代码来源:google.go

示例3: Register

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]))
		}})
}
开发者ID:Kaioshi,项目名称:Kari,代码行数:35,代码来源:urbandictionary.go

示例4: Register

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
		}})
}
开发者ID:Kaioshi,项目名称:Kari,代码行数:38,代码来源:youtube.go

示例5: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Alias Frontend plugin"))

	events.CmdListen(&events.CmdListener{
		Command: "var",
		Help:    "Allows you to set variables.",
		Syntax: fmt.Sprintf("%svar <add/remove/list/info> <varname> [<data>] - Example: %svar add butts are nice",
			bot.Config.Prefix, bot.Config.Prefix),
		Callback: func(input *events.Params) {
			var argLen int = len(input.Args)
			if argLen == 0 {
				bot.Say(input.Context, events.Help("var", "syntax"))
				return
			}
			switch strings.ToLower(input.Args[0]) {
			case "add":
				if argLen < 3 {
					bot.Say(input.Context, events.Help("var", "syntax"))
					return
				}
				alias.Vars.SaveOne(input.Args[1], strings.Join(input.Args[2:], " "))
				bot.Say(input.Context, "Added!")
			case "remove":
				if argLen < 2 {
					bot.Say(input.Context, events.Help("var", "syntax"))
					return
				}
				if ok := alias.Vars.RemoveOne(input.Args[1]); ok {
					bot.Say(input.Context, "Removed!")
				} else {
					bot.Say(input.Context, fmt.Sprintf("There is no %q variable.", input.Args[1]))
				}
			case "info":
				if argLen < 2 {
					bot.Say(input.Context, events.Help("var", "syntax"))
					return
				}
				varInfo := alias.Vars.GetOne(input.Args[1])
				if varInfo == "" {
					bot.Say(input.Context, fmt.Sprintf("There is no %q variable.", input.Args[1]))
				} else {
					bot.Say(input.Context, fmt.Sprintf("Variable %q contains: %s", input.Args[1], varInfo))
				}
			case "list":
				variables := alias.Vars.GetKeys()
				if len(variables) == 0 {
					bot.Say(input.Context, "There are no variables defined.")
				} else {
					bot.Say(input.Context, fmt.Sprintf("Variables: %s", strings.Join(variables, ", ")))
				}
			default:
				bot.Say(input.Context, events.Help("var", "syntax"))
			}
		}})

	events.CmdListen(&events.CmdListener{
		Command: "alias",
		Help:    "Aliases things!",
		Syntax: fmt.Sprintf("%salias <add/remove/list/info> <command> <args> - Example: %salias add whip action whips {args*}'s buttocks!",
			bot.Config.Prefix, bot.Config.Prefix),
		Callback: func(input *events.Params) {
			var argLen int = len(input.Args)
			if argLen == 0 {
				bot.Say(input.Context, events.Help("alias", "syntax"))
				return
			}
			switch strings.ToLower(input.Args[0]) {
			case "list":
				aliases := alias.DB.GetKeys()
				if len(aliases) == 0 {
					bot.Say(input.Context, "There are no aliases defined.")
				} else {
					bot.Say(input.Context, fmt.Sprintf("Aliases: %s", strings.Join(aliases, ", ")))
				}
			case "info":
				if argLen < 2 {
					bot.Say(input.Context, events.Help("alias", "syntax"))
					return
				}
				aliasInfo := alias.DB.GetOne(input.Args[1])
				if aliasInfo == "" {
					bot.Say(input.Context, fmt.Sprintf("There is no %q alias.", input.Args[1]))
				} else {
					bot.Say(input.Context, fmt.Sprintf("Alias %q contains: %s", input.Args[1], aliasInfo))
				}
			case "add":
				if argLen < 3 {
					bot.Say(input.Context, events.Help("alias", "syntax"))
					return
				}
				alias.DB.SaveOne(input.Args[1], strings.Join(input.Args[2:], " "))
				bot.Say(input.Context, "Added!")
			case "remove":
				if argLen < 2 {
					bot.Say(input.Context, events.Help("alias", "syntax"))
					return
				}
				if ok := alias.DB.RemoveOne(input.Args[1]); ok {
					bot.Say(input.Context, "Removed!")
				} else {
//.........这里部分代码省略.........
开发者ID:Kaioshi,项目名称:Kari,代码行数:101,代码来源:aliasfrontend.go

示例6: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Internal Address List plugin"))

	events.CmdListen(&events.CmdListener{
		Command: "ial",
		Help:    "Shows ial internal details",
		Syntax:  "TBD",
		Callback: func(input *events.Params) {
			fmt.Println(globals.Channels)
		}})

	events.EvListen(&events.EvListener{ // grab our nick on connect
		Handle: "ial001",
		Event:  "001",
		Callback: func(input *events.Params) {
			bot.Info.Nick = input.Args[1]
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialJoin",
		Event:  "JOIN",
		Callback: func(input *events.Params) {
			if input.Nick == bot.Info.Nick {
				bot.Send("WHO " + input.Context)
				bot.Send("MODE " + input.Context)
				if bot.Info.User == "" {
					bot.Info.User = input.Nick + "!" + input.Address
				}
				bot.Info.Channels.Add(input.Context)
				chdata := &globals.ChannelData{User: make(map[string]*globals.UserData)}
				globals.Channels[strings.ToLower(input.Context)] = chdata
			} else {
				globals.Channels[strings.ToLower(input.Context)].User[strings.ToLower(input.Nick)] = &globals.UserData{
					Nick:     input.Nick,
					User:     input.Address[:strings.Index(input.Address, "@")],
					Address:  input.Address[strings.Index(input.Address, "@")+1:],
					Fulluser: input.Args[0][1:],
				}
			}
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialPart",
		Event:  "PART",
		Callback: func(input *events.Params) {
			if input.Nick == bot.Info.Nick {
				delete(globals.Channels, strings.ToLower(input.Context))
			} else {
				delete(globals.Channels[strings.ToLower(input.Context)].User, strings.ToLower(input.Nick))
			}
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialKick",
		Event:  "KICK",
		Callback: func(input *events.Params) {
			for channel, _ := range globals.Channels {
				for key, user := range globals.Channels[channel].User {
					if user.Nick == input.Kicknick {
						delete(globals.Channels[channel].User, key)
					}
				}
			}
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialQuit",
		Event:  "QUIT",
		Callback: func(input *events.Params) {
			for channel, _ := range globals.Channels {
				for key, user := range globals.Channels[channel].User {
					if user.Nick == input.Nick {
						delete(globals.Channels[channel].User, key)
					}
				}
			}
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialNick",
		Event:  "NICK",
		Callback: func(input *events.Params) {
			for channel, _ := range globals.Channels {
				for key, user := range globals.Channels[channel].User {
					if user.Nick == input.Nick {
						newuser := &globals.UserData{ // assigned in this order because of pure case nick changes
							Nick:     input.Newnick, // ie nick -> NICK
							User:     user.User,
							Address:  user.Address,
							Fulluser: input.Newnick + "!" + user.User + "@" + user.Address,
						}
						delete(globals.Channels[channel].User, key)
						globals.Channels[channel].User[strings.ToLower(input.Newnick)] = newuser
					}
				}
			}
		}})

	events.EvListen(&events.EvListener{
		Handle: "ialWho",
//.........这里部分代码省略.........
开发者ID:Kaioshi,项目名称:Kari,代码行数:101,代码来源:ial.go

示例7: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(time.Now(), "Loading the MangaStream plugin"))

	timer.AddEvent("Checking Manga Sources", 900, func() {
		checkUpdates(bot, "mangafox", "")
		checkUpdates(bot, "mangastream", "")
	})

	events.CmdListen(&events.CmdListener{
		Commands: []string{"mangastream", "ms"},
		Help:     "Manages the MangaStream release watcher",
		Syntax: fmt.Sprintf("%sms <add/remove/list> <manga title> - Example: %sms add One Piece",
			bot.Config.Prefix, bot.Config.Prefix),
		Callback: func(input *events.Params) {
			if len(input.Args) == 0 {
				bot.Say(input.Context, events.Help("ms", "syntax"))
				return
			}
			var manga Manga
			loadWatched(&manga)
			switch strings.ToLower(input.Args[0]) {
			case "list":
				if len(manga.MangaStream) == 0 {
					bot.Say(input.Context, "I'm not watching for any MangaStream releases right now. :<")
					return
				}
				var titles string
				for _, entry := range manga.MangaStream {
					if entry.Manga == "" {
						titles += entry.Title + ", "
					} else {
						titles += entry.Manga + ", "
					}
				}
				bot.Say(input.Context, fmt.Sprintf("I'm currently watching for %s updates to %s.",
					"MangaStream", titles[:len(titles)-2]))
			case "add":
				if len(input.Args) < 2 {
					bot.Say(input.Context, events.Help("ms", "syntax"))
					return
				}
				bot.Say(input.Context, addManga(&manga, strings.Join(input.Args[1:], " "), input.Context, "MangaStream", bot))
			case "remove":
				if len(input.Args) < 2 {
					bot.Say(input.Context, events.Help("ms", "syntax"))
					return
				}
				bot.Say(input.Context, removeManga(&manga, strings.Join(input.Args[1:], " "), "MangaStream"))
			case "check":
				checkUpdates(bot, "mangastream", input.Context)
			}
		}})

	events.CmdListen(&events.CmdListener{ // not sure how to make this neat yet ^ v
		Commands: []string{"mangafox", "mf"},
		Help:     "Manages the MangaFox release watcher",
		Syntax: fmt.Sprintf("%smf <add/remove/list> <manga title> - Example: %smf add One Piece",
			bot.Config.Prefix, bot.Config.Prefix),
		Callback: func(input *events.Params) {
			if len(input.Args) == 0 {
				bot.Say(input.Context, events.Help("mf", "syntax"))
				return
			}
			var manga Manga
			loadWatched(&manga)
			switch strings.ToLower(input.Args[0]) {
			case "list":
				if len(manga.MangaFox) == 0 {
					bot.Say(input.Context, "I'm not watching for any MangaFox releases right now. :<")
					return
				}
				var titles string
				for _, entry := range manga.MangaFox {
					if entry.Manga == "" {
						titles += entry.Title + ", "
					} else {
						titles += entry.Manga + ", "
					}
				}
				bot.Say(input.Context, fmt.Sprintf("I'm currently watching for %s updates to %s.",
					"MangaFox", titles[:len(titles)-2]))
			case "add":
				if len(input.Args) < 2 {
					bot.Say(input.Context, events.Help("mf", "syntax"))
					return
				}
				bot.Say(input.Context, addManga(&manga, strings.Join(input.Args[1:], " "), input.Context, "MangaFox", bot))
			case "remove":
				if len(input.Args) < 2 {
					bot.Say(input.Context, events.Help("mf", "syntax"))
					return
				}
				bot.Say(input.Context, removeManga(&manga, strings.Join(input.Args[1:], " "), "MangaFox"))
			case "check":
				checkUpdates(bot, "mangafox", input.Context)
			}
		}})
}
开发者ID:Kaioshi,项目名称:Kari,代码行数:98,代码来源:manga.go

示例8: 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

示例9: Register

func Register(bot *irc.IRC) {
	defer logger.Info(lib.TimeTrack(lib.TimeNow(), "Loading the Core plugin"))

	// autojoin
	events.EvListen(&events.EvListener{
		Handle: "autojoin",
		Event:  "376",
		Callback: func(input *events.Params) {
			bot.Join(strings.Join(bot.Config.Autojoin, ","))
		}})

	// nick is taken
	events.EvListen(&events.EvListener{
		Handle: "nickTaken",
		Event:  "433",
		Callback: func(input *events.Params) {
			bot.Config.Nicknames = append(bot.Config.Nicknames[:0], bot.Config.Nicknames[1:]...)
			bot.Send("NICK " + bot.Config.Nicknames[0])
		}})

	events.CmdListen(&events.CmdListener{
		Command: "help",
		Help:    "Helps!",
		Syntax:  bot.Config.Prefix + "help [<command>] - Example: " + bot.Config.Prefix + "help help",
		Callback: func(input *events.Params) {
			commands := events.CommandList()
			if len(input.Args) == 0 {
				bot.Say(input.Context, fmt.Sprintf("Commands: %s", strings.Join(commands, ", ")))
				return
			}
			input.Args[0] = strings.ToLower(input.Args[0])
			for _, command := range commands {
				if input.Args[0] == command {
					bot.Say(input.Context, events.Help(command, "help"))
					bot.Say(input.Context, events.Help(command, "syntax"))
					return
				}
			}
			bot.Say(input.Context, fmt.Sprintf("\"%s\" isn't a command.", input.Args[0]))
		}})

	// say
	events.CmdListen(&events.CmdListener{
		Command: "say",
		Help:    "Says stuff!",
		Syntax:  bot.Config.Prefix + "say <thing you want to say>",
		Callback: func(input *events.Params) {
			bot.Say(input.Context, input.Data)
		}})

	// action
	events.CmdListen(&events.CmdListener{
		Command: "action",
		Help:    "/me's stuff!",
		Syntax:  bot.Config.Prefix + "action <thing you want the bot to emote>",
		Callback: func(input *events.Params) {
			bot.Action(input.Context, input.Data)
		}})

	// join
	events.CmdListen(&events.CmdListener{
		Command: "join",
		Help:    "Joins channels!",
		Syntax:  bot.Config.Prefix + "join #channel",
		Callback: func(input *events.Params) {
			if len(input.Args) < 1 || input.Args[0][0:1] != "#" {
				bot.Say(input.Context, "That ain't how you join a channel sucka")
				return
			}
			bot.Join(input.Args[0])
		}})

	// part
	events.CmdListen(&events.CmdListener{
		Command: "part",
		Help:    "Parts channels!",
		Syntax:  bot.Config.Prefix + "part #channel",
		Callback: func(input *events.Params) {
			if len(input.Args) < 1 {
				if input.Context[0:1] == "#" {
					bot.Part(input.Context)
				} else {
					bot.Say(input.Context, "Either specify the channel to part or use the command in the channel.")
				}
			} else if input.Args[0][0:1] != "#" {
				bot.Say(input.Context, "That ain't how you part a channel sucka")
				return
			} else {
				bot.Part(input.Args[0])
			}
		}})

	// raw
	events.CmdListen(&events.CmdListener{
		Command: "raw",
		Help:    "Sends raw commands to the server",
		Syntax:  bot.Config.Prefix + "raw <command>",
		Callback: func(input *events.Params) {
			bot.Send(input.Data)
		}})
//.........这里部分代码省略.........
开发者ID:Kaioshi,项目名称:Kari,代码行数:101,代码来源:core.go


注:本文中的Kari/irc.IRC类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。