Пример #1
0
// Load loads configuration data from the given ini file.
func (c *Config) Load(file string) (err error) {
	ini := ini.New()
	err = ini.Load(file)

	if err != nil {
		return
	}

	s := ini.Section("net")
	c.Address = fmt.Sprintf("%s:%d", s.S("host", ""), s.U32("port", 0))
	c.SSLKey = s.S("x509-key", "")
	c.SSLCert = s.S("x509-cert", "")

	chans := s.List("channels")
	c.Channels = make([]*irc.Channel, len(chans))

	// Parse channel definitions. A single channel comes as a string like:
	//
	//    <name>,<key>,<chanservpassword>
	//
	// The name is the only required value.
	for i, line := range chans {
		elements := strings.Split(line, ",")

		for k := range elements {
			elements[k] = strings.TrimSpace(elements[k])
		}

		if len(elements) == 0 || len(elements[0]) == 0 {
			continue
		}

		var ch irc.Channel
		ch.Name = elements[0]

		if len(elements) > 1 {
			ch.Key = elements[1]
		}

		if len(elements) > 2 {
			ch.ChanservPassword = elements[2]
		}

		c.Channels[i] = &ch
	}

	s = ini.Section("account")
	c.Nickname = s.S("nickname", "")
	c.ServerPassword = s.S("server-password", "")
	c.OperPassword = s.S("oper-password", "")
	c.NickservPassword = s.S("nickserv-password", "")
	c.QuitMessage = s.S("quit-message", "")

	c.CommandPrefix = ini.Section("bot").S("command-prefix", "?")
	c.Whitelist = ini.Section("whitelist").List("user")
	return
}
Пример #2
0
func (p *Plugin) Load(c *proto.Client) (err error) {
	err = p.Base.Load(c)
	if err != nil {
		return
	}

	comm := new(cmd.Command)
	comm.Name = "quit"
	comm.Description = "Unconditionally quit the bot program"
	comm.Restricted = true
	comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
		c.Quit("")
	}
	cmd.Register(comm)

	comm = new(cmd.Command)
	comm.Name = "join"
	comm.Description = "Join the given channel"
	comm.Restricted = true
	comm.Params = []cmd.Param{
		{Name: "channel", Optional: false, Pattern: cmd.RegChannel},
		{Name: "key", Optional: true, Pattern: cmd.RegAny},
		{Name: "chanservpass", Optional: true, Pattern: cmd.RegAny},
	}
	comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
		var ch irc.Channel
		ch.Name = cmd.Params[0].Value

		if len(cmd.Params) > 1 {
			ch.Key = cmd.Params[1].Value
		}

		if len(cmd.Params) > 2 {
			ch.ChanservPassword = cmd.Params[2].Value
		}

		c.Join(&ch)
	}
	cmd.Register(comm)

	comm = new(cmd.Command)
	comm.Name = "leave"
	comm.Description = "Leave the given channel"
	comm.Restricted = true
	comm.Params = []cmd.Param{
		{Name: "channel", Optional: true, Pattern: cmd.RegChannel},
	}
	comm.Execute = func(cmd *cmd.Command, c *proto.Client, m *proto.Message) {
		var ch irc.Channel

		if len(cmd.Params) > 0 {
			ch.Name = cmd.Params[0].Value
		} else {
			if !m.FromChannel() {
				return
			}
			ch.Name = m.Receiver
		}

		c.Part(&ch)
	}
	cmd.Register(comm)

	return
}