// Init initializes the plugin. it loads configuration data and binds // commands and protocol handlers. func (p *Plugin) Load(c *proto.Client) (err error) { err = p.Base.Load(c) if err != nil { return } c.Bind(proto.CmdPrivMsg, func(c *proto.Client, m *proto.Message) { p.parseURL(c, m) }) ini := p.LoadConfig() if ini == nil { return } s := ini.Section("exclude") list := s.List("url") p.exclude = make([]*regexp.Regexp, len(list)) for i := range list { p.exclude[i], err = regexp.Compile(list[i]) if err != nil { return } } return }
// bind binds protocol message handlers. func bind(c *proto.Client) { c.Bind(proto.Unknown, onAny) c.Bind(proto.CmdPing, onPing) c.Bind(proto.EndOfMOTD, onJoinChannels) c.Bind(proto.ErrNoMOTD, onJoinChannels) c.Bind(proto.ErrNicknameInUse, onNickInUse) c.Bind(proto.CmdPrivMsg, onPrivMsg) }
// 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) }