aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 19:02:26 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 19:02:26 +0100
commita4dd3b310d68f5c6147bdeaf8ecd3556c2cf7859 (patch)
tree14d4dbdcc03803f4a40b06f2862bce78df318a76 /connector
parent531b59bf953ad6c1fb7adfb6554dcc412fbe47e5 (diff)
downloadeasybridge-a4dd3b310d68f5c6147bdeaf8ecd3556c2cf7859.tar.gz
easybridge-a4dd3b310d68f5c6147bdeaf8ecd3556c2cf7859.zip
Go fmt
Diffstat (limited to 'connector')
-rw-r--r--connector/connector.go11
-rw-r--r--connector/irc/irc.go38
2 files changed, 25 insertions, 24 deletions
diff --git a/connector/connector.go b/connector/connector.go
index 9ff5d49..2b54258 100644
--- a/connector/connector.go
+++ b/connector/connector.go
@@ -8,11 +8,11 @@ package connector
- A connector represents a connection to an outgoing service (IRC, XMPP, etc)
It satisfies a generic interface representing the actions that can be called
(send messages, join room, etc)
-
+
- A handler represents a consumer of events happening on a connection
It satisfies a generic interface representing the events that can happend
(message received, rooms autojoined, etc)
-
+
- A connector implements a given protocol that has an identifier
Each protocol identifier determines a namespace for user identifiers
and room identifiers which are globally unique for all connections using
@@ -82,6 +82,7 @@ type Handler interface {
}
type EventType int
+
const (
EVENT_JOIN EventType = iota
EVENT_LEAVE
@@ -114,12 +115,12 @@ type Event struct {
type UserInfo struct {
DisplayName string
- Avatar MediaObject
+ Avatar MediaObject
}
type RoomInfo struct {
- Name string
- Topic string
+ Name string
+ Topic string
Picture MediaObject
}
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index ccbd803..318c663 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -1,10 +1,10 @@
package irc
import (
- "time"
+ "fmt"
_ "os"
"strings"
- "fmt"
+ "time"
"github.com/lrstanley/girc"
@@ -19,19 +19,19 @@ type IRC struct {
handler Handler
connected bool
- timeout int
+ timeout int
- nick string
- name string
+ nick string
+ name string
server string
- conn *girc.Client
+ conn *girc.Client
}
func (irc *IRC) SetHandler(h Handler) {
irc.handler = h
}
-func(irc *IRC) Protocol() string {
+func (irc *IRC) Protocol() string {
return "irc"
}
@@ -64,9 +64,9 @@ func (irc *IRC) Configure(c Configuration) error {
client := girc.New(girc.Config{
Server: irc.server,
- Port: port,
- Nick: irc.nick,
- User: irc.nick,
+ Port: port,
+ Nick: irc.nick,
+ User: irc.nick,
//Out: os.Stderr,
SSL: ssl,
})
@@ -85,7 +85,7 @@ func (irc *IRC) Configure(c Configuration) error {
go irc.connectLoop(client)
for i := 0; i < 42; i++ {
- time.Sleep(time.Duration(1)*time.Second)
+ time.Sleep(time.Duration(1) * time.Second)
if irc.conn != client {
break
}
@@ -245,9 +245,9 @@ func (irc *IRC) ircConnected(c *girc.Client, e girc.Event) {
func (irc *IRC) ircPrivmsg(c *girc.Client, e girc.Event) {
ev := &Event{
- Type: EVENT_MESSAGE,
+ Type: EVENT_MESSAGE,
Author: UserID(e.Source.Name + "@" + irc.server),
- Text: e.Last(),
+ Text: e.Last(),
}
if e.IsFromChannel() {
ev.Room = RoomID(e.Params[0] + "@" + irc.server)
@@ -265,9 +265,9 @@ func (irc *IRC) ircJoin(c *girc.Client, e girc.Event) {
} else {
user := UserID(e.Source.Name + "@" + irc.server)
ev := &Event{
- Type: EVENT_JOIN,
+ Type: EVENT_JOIN,
Author: user,
- Room: room,
+ Room: room,
}
irc.handler.Event(ev)
irc.handler.UserInfoUpdated(user, &UserInfo{
@@ -283,9 +283,9 @@ func (irc *IRC) ircPart(c *girc.Client, e girc.Event) {
} else {
user := UserID(e.Source.Name + "@" + irc.server)
ev := &Event{
- Type: EVENT_LEAVE,
+ Type: EVENT_LEAVE,
Author: user,
- Room: room,
+ Room: room,
}
irc.handler.Event(ev)
irc.handler.UserInfoUpdated(user, &UserInfo{
@@ -304,9 +304,9 @@ func (irc *IRC) ircNamreply(c *girc.Client, e girc.Event) {
src := girc.ParseSource(name)
if src.Name != irc.nick {
irc.handler.Event(&Event{
- Type: EVENT_JOIN,
+ Type: EVENT_JOIN,
Author: UserID(src.Name + "@" + irc.server),
- Room: room,
+ Room: room,
})
}
}