Beispiel #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
}
Beispiel #2
0
// LoadConfig reads the ini configuration file for the given plugin.
// Returns nil if the file does not exist.
func (p *Base) LoadConfig() *ini.File {
	ini := ini.New()
	err := ini.Load(configPath(p.profile, p.name))

	if err != nil {
		return nil
	}

	return ini
}
Beispiel #3
0
// Init initializes the plugin. it loads configuration data and binds
// commands and protocol handlers.
func Init(profile string, c *proto.Client) {
	log.Println("Initializing: url")

	ini := ini.New()
	err := ini.Load(plugin.ConfigPath(profile, "url"))

	if err != nil {
		log.Fatal(err)
	}

	s := ini.Section("exclude")
	list := s.List("url")
	exclude = make([]*regexp.Regexp, len(list))

	for i := range list {
		exclude[i], err = regexp.Compile(list[i])
		if err != nil {
			log.Fatalf("- Invalid pattern: %s", list[i])
		}
	}

	c.Bind(proto.CmdPrivMsg, parseURL)
}