diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -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 + } +} |