1// This program is free software: you can redistribute it and/or modify 2// it under the terms of the GNU Affero General Public License as 3// published by the Free Software Foundation, either version 3 of the 4// License, or (at your option) any later version. 5// 6// This program is distributed in the hope that it will be useful, but 7// WITHOUT ANY WARRANTY; without even the implied warranty of 8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 9// Affero General Public License for more details.10//11// You should have received a copy of the GNU Affero General Public12// License along with this program. If not, see <http://www.gnu.org/licenses/>.1314package rejoin1516import (17 "github.com/nmeum/marvin/irc"18 "github.com/nmeum/marvin/modules"19 "strings"20 "time"21)2223type Module struct {24 Timeout string `json:"timeout"`25}2627func Init(moduleSet *modules.ModuleSet) {28 moduleSet.Register(new(Module))29}3031func (m *Module) Name() string {32 return "rejoin"33}3435func (m *Module) Help() string {36 return "Enables automatic reconnection on kick."37}3839func (m *Module) Defaults() {40 m.Timeout = "0m3s"41}4243func (m *Module) Load(client *irc.Client) error {44 duration, err := time.ParseDuration(m.Timeout)45 if err != nil {46 return err47 }4849 client.CmdHook("kick", func(c *irc.Client, msg irc.Message) error {50 if msg.Data != client.Nickname {51 return nil52 }5354 time.Sleep(duration)55 return c.Write("JOIN %s", strings.Fields(msg.Receiver)[0])56 })5758 return nil59}