IRC autorejoin on reconnect

This commit is contained in:
Alex 2020-05-04 18:54:45 +02:00
parent 73fa488402
commit d7973a98fe

View file

@ -25,6 +25,8 @@ type IRC struct {
name string
server string
conn *girc.Client
joinedRooms map[string]bool
}
func (irc *IRC) SetHandler(h Handler) {
@ -95,6 +97,8 @@ func (irc *IRC) Configure(c Configuration) error {
client.Handlers.Add(girc.TOPIC, irc.ircTopic)
client.Handlers.Add(girc.RPL_TOPIC, irc.ircRplTopic)
irc.joinedRooms = make(map[string]bool)
irc.conn = client
go irc.connectLoop(client)
@ -300,6 +304,12 @@ func (irc *IRC) ircConnected(c *girc.Client, e girc.Event) {
irc.handler.SystemMessage("Connected to IRC.")
irc.timeout = 10
irc.connected = true
for room, joined := range irc.joinedRooms {
if joined {
irc.conn.Cmd.Join(room)
}
}
}
func (irc *IRC) ircPrivmsg(c *girc.Client, e girc.Event) {
@ -321,6 +331,7 @@ func (irc *IRC) ircJoin(c *girc.Client, e girc.Event) {
room := RoomID(e.Params[0] + "@" + irc.server)
if e.Source.Name == irc.nick {
irc.handler.Joined(room)
irc.joinedRooms[e.Params[0]] = true
} else {
user := UserID(e.Source.Name + "@" + irc.server)
ev := &Event{
@ -339,6 +350,7 @@ func (irc *IRC) ircPart(c *girc.Client, e girc.Event) {
room := RoomID(e.Params[0] + "@" + irc.server)
if e.Source.Name == irc.nick {
irc.handler.Left(room)
delete(irc.joinedRooms, e.Params[0])
} else {
user := UserID(e.Source.Name + "@" + irc.server)
ev := &Event{