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


Golang IRC.Send方法代码示例

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


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

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

示例2: 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.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。