aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-05-04 18:54:45 +0200
committerAlex Auvolat <alex@adnab.me>2020-05-04 18:54:45 +0200
commitd7973a98fe0f79100201a320bccccc680952d359 (patch)
tree5ba903ecfc12c6368102e47676332799bbc25f7c /connector
parent73fa488402494c69acf5b82a4d101dd49ce00eef (diff)
downloadeasybridge-d7973a98fe0f79100201a320bccccc680952d359.tar.gz
easybridge-d7973a98fe0f79100201a320bccccc680952d359.zip
IRC autorejoin on reconnect
Diffstat (limited to 'connector')
-rw-r--r--connector/irc/irc.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index 19e73fc..77388e7 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -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{