diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-16 16:41:13 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-16 16:41:13 +0100 |
commit | b7f0776784b6e5fe0f0a028c2913f58e995afa73 (patch) | |
tree | 4a0c92199c5b313847954f685d61a93bb6463aed | |
parent | ec67a610e3062d3e60891332f33ace4ad5a448bd (diff) | |
download | easybridge-b7f0776784b6e5fe0f0a028c2913f58e995afa73.tar.gz easybridge-b7f0776784b6e5fe0f0a028c2913f58e995afa73.zip |
Invitations, closing before configure, etc
-rw-r--r-- | connector/connector.go | 3 | ||||
-rw-r--r-- | connector/irc/irc.go | 44 | ||||
-rw-r--r-- | main.go | 4 |
3 files changed, 46 insertions, 5 deletions
diff --git a/connector/connector.go b/connector/connector.go index 2116bb5..9894bfc 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -48,6 +48,9 @@ type Connector interface { // If no error happens, it must fire a Handler.Joined event Join(roomId RoomID) error + // Try to invite someone to a channel + Invite(user UserID, roomId RoomID) error + // Leave a channel Leave(roomId RoomID) diff --git a/connector/irc/irc.go b/connector/irc/irc.go index 02f82eb..b9c58ad 100644 --- a/connector/irc/irc.go +++ b/connector/irc/irc.go @@ -36,6 +36,10 @@ func(irc *IRC) Protocol() string { } func (irc *IRC) Configure(c Configuration) error { + if irc.conn != nil { + irc.Close() + } + irc.config = c irc.nick = c.GetString("nick") @@ -54,7 +58,7 @@ func (irc *IRC) Configure(c Configuration) error { Port: port, Nick: irc.nick, User: irc.nick, - Debug: os.Stderr, + Out: os.Stderr, SSL: true, }) @@ -132,6 +136,21 @@ func (irc *IRC) Join(roomId RoomID) error { return nil } +func (irc *IRC) Invite(userId UserID, roomId RoomID) error { + ch, err := irc.checkRoomId(roomId) + if err != nil { + return err + } + + who, err := irc.checkUserId(userId) + if err != nil { + return err + } + + irc.conn.Cmd.Invite(ch, who) + return nil +} + func (irc *IRC) Leave(roomId RoomID) { ch, err := irc.checkRoomId(roomId) if err != nil { @@ -247,9 +266,28 @@ func (irc *IRC) ircPart(c *girc.Client, e girc.Event) { } func (irc *IRC) ircNamreply(c *girc.Client, e girc.Event) { - fmt.Printf("TODO namreply params: %#v", e.Params) + room := RoomID(e.Params[2] + "@" + irc.server) + names := strings.Split(e.Last(), " ") + for _, name := range names { + if name[0] == '@' { + name = name[1:] + } + src := girc.ParseSource(name) + if src.Name != irc.nick { + irc.handler.Event(&Event{ + Type: EVENT_JOIN, + Author: UserID(src.Name + "@" + irc.server), + Room: room, + }) + } + } } func (irc *IRC) ircTopic(c *girc.Client, e girc.Event) { - fmt.Printf("TODO topic params: %#v", e.Params) + room := RoomID(e.Params[1] + "@" + irc.server) + topic := e.Last() + irc.handler.RoomInfoUpdated(room, &RoomInfo{ + Name: string(room), + Description: topic, + }) } @@ -86,8 +86,8 @@ func main() { log.Fatalf("Send: %s", err) } - fmt.Printf("waiting exit signal") + fmt.Printf("waiting exit signal\n") <-h.exit - fmt.Printf("got exit signal") + fmt.Printf("got exit signal\n") irc.Close() } |