aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go30
1 files changed, 18 insertions, 12 deletions
diff --git a/main.go b/main.go
index 1b3971e..a8a349c 100644
--- a/main.go
+++ b/main.go
@@ -24,7 +24,6 @@ import (
type ConfigAccount struct {
Protocol string `json:"protocol"`
- Rooms []string `json:"rooms"`
Config map[string]string `json:"config"`
}
@@ -176,27 +175,21 @@ func main() {
for user, accounts := range config.Accounts {
for name, params := range accounts {
- var conn connector.Connector
- switch params.Protocol {
- case "irc":
- conn = &irc.IRC{}
- case "xmpp":
- conn = &xmpp.XMPP{}
- case "mattermost":
- conn = &mattermost.Mattermost{}
- default:
- log.Fatalf("Invalid protocol %s", params.Protocol)
+ conn := createConnector(params.Protocol)
+ if conn == nil {
+ log.Fatalf("Could not create connector for protocol %s", params.Protocol)
}
account := &Account{
MatrixUser: fmt.Sprintf("@%s:%s", user, config.MatrixDomain),
AccountName: name,
Protocol: params.Protocol,
+ Config: params.Config,
Conn: conn,
JoinedRooms: map[connector.RoomID]bool{},
}
conn.SetHandler(account)
AddAccount(account)
- go account.connect(params.Config, params.Rooms)
+ go account.connect(params.Config)
}
}
@@ -205,3 +198,16 @@ func main() {
log.Fatal(err)
}
}
+
+func createConnector(protocol string) connector.Connector {
+ switch protocol {
+ case "irc":
+ return &irc.IRC{}
+ case "xmpp":
+ return &xmpp.XMPP{}
+ case "mattermost":
+ return &mattermost.Mattermost{}
+ default:
+ return nil
+ }
+}