// modify executes the requested changes func (c *Command) modify() bool { effective := false cnf := configuration.Config for _, n := range c.toStart.Commands { if _, ok := plugins.Commands[n]; ok { cnf.Commands = append(cnf.Commands, n) effective = true } } for _, n := range c.toStart.Middlewares { if _, ok := plugins.Middlewares[n]; ok { cnf.Middlewares = append(cnf.Middlewares, n) effective = true } } for _, n := range c.toStop.Commands { if _, ok := plugins.Commands[n]; ok && utils.StringInSlice(n, cnf.Commands) { cnf.Commands, _ = utils.RemoveStringInSlice(n, cnf.Commands) plugins.Commands[n].Stop() effective = true } } for _, n := range c.toStop.Middlewares { if _, ok := plugins.Middlewares[n]; ok && utils.StringInSlice(n, cnf.Middlewares) { cnf.Middlewares, _ = utils.RemoveStringInSlice(n, cnf.Middlewares) plugins.Middlewares[n].Stop() effective = true } } plugins.Start() return effective }
// IsURLToTreat checks whether the host is already managed by another plugin or not func IsURLToTreat(host string) bool { m := configuration.Config.Middlewares // If middlewares youtube or github are disabled, we still get the // title of these sites. if (host != "youtu.be" && host != "youtube.com" || !utils.StringInSlice("yt", m)) && (host != "github.com" || !utils.StringInSlice("github", m)) { return true } return false }
// Start starts the middleware and returns any occurred error, nil otherwise func (m *Middleware) Start() error { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { CreateBucket() m.Started = true } return nil }
// Get actually executes the command. func (c *Command) Get(ib *irc.Connection, from string, to string, args []string) { if to == configuration.Config.BotName { to = from } if !utils.StringInSlice(from, configuration.Config.Admins) { ib.Notice(to, "You are not a registered admin.") return } if c.pending { ib.Notice(to, "Wait for other operations to complete") return } c.pending = true ib.AddCallback("330", func(e *irc.Event) { c.auth = true ib.ClearCallback("330") }) ib.AddCallback("318", func(e *irc.Event) { ib.ClearCallback("318") time.Sleep(1 * time.Second) if !c.auth { ib.Notice(to, "You must identify to nickserv in order to use this plugin.") c.pending = false return } c.processArgs(ib, to) }) c.args = args ib.Whois(from) }
// Start starts the plugin and returns any occurred error, nil otherwise func (c *Command) Start() error { if utils.StringInSlice(command, configuration.Config.Commands) { CreateBucket() c.Started = true } return nil }
// Start starts the middleware and returns any occurred error, nil otherwise func (m *Middleware) Start() error { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { if err := InitLoggers(); err != nil { return fmt.Errorf("Error init loggers : %s\n", err) } m.Started = true } return nil }
// Start starts the middleware and returns any occurred error, nil otherwise func (m *Middleware) Start() error { if utils.StringInSlice(middlewareName, configuration.Config.Middlewares) { MainChain = NewChain("main") if err := database.BotStorage.CreateBucket(bucketName); err != nil { return fmt.Errorf("While initializing Markov middleware : %s", err) } database.BotStorage.Get(bucketName, MainChain.Key, MainChain) m.Started = true } return nil }
// Start starts the plugin and returns any occurred error, nil otherwise func (c *Command) Start() error { if utils.StringInSlice(command, configuration.Config.Commands) { if err := database.BotStorage.CreateBucket(bucketName); err != nil { log.Fatalf("Error while creating bucket for the Karma plugin : %s", err) } d := Data{make(map[string]int)} database.BotStorage.Get(bucketName, mainKey, &d) plugins.Commands[command] = &Command{true, d, make(map[string]time.Time)} } return nil }
func (c *Command) admins() bool { var effective = false cnf := configuration.Config for _, i := range c.args[1:] { if strings.HasPrefix(i, "-") { cnf.Admins, _ = utils.RemoveStringInSlice(i[1:], cnf.Admins) effective = true } else if strings.HasPrefix(i, "+") && !utils.StringInSlice(i[1:], cnf.Admins) { cnf.Admins = append(cnf.Admins, i[1:]) effective = true } } return effective }