// ModuleReload will reload a module by telling the handler to signal a kill cleanup to the module // being reloaded. If the module refuses to be killed for whatever reason, reloading of the module // will be aborted. If the module complies, the module's corresponding process will be killed. The // module will then be recompiled if need be and will be restarted after. func (b *Bot) ModuleReload(name string) (err error) { module, ok := b.Modules[strings.ToLower(name)] if !ok { return errors.New("Module is unknown to the bot") } if module.PM.IsRunning() { err = b.Handler.SignalCleanup(ModuleName(name)) if err != nil { rlog.Error("Bot", "Error while cleaning up module "+name+": "+err.Error()) return errors.New("Module did not cleanup, aborting reload") } module.PM.Kill() <-module.PM.Wait() } res := module.PM.Recompile() if res != nil && res.Err != nil { rlog.Errorf("Bot", "Could not recompile module %s\n ----\n%s\n ----\n\n", module.Name, res.Output) return errors.New("Could not recompile module") } b.moduleStart(name) return nil }
// DefaultConnect will connect to IRC and start listening. It will not log anything. func (b *Bot) DefaultConnect() { err := b.Connect() if err != nil { rlog.Errorf("Bot", "Could not connect to irc server: %s\n ----\n The bot will now exit\n") os.Exit(1) } b.Listen() }