Go fmt
This commit is contained in:
parent
531b59bf95
commit
a4dd3b310d
9 changed files with 142 additions and 144 deletions
|
@ -10,10 +10,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
MatrixUser string
|
MatrixUser string
|
||||||
AccountName string
|
AccountName string
|
||||||
Protocol string
|
Protocol string
|
||||||
Conn Connector
|
Conn Connector
|
||||||
|
|
||||||
JoinedRooms map[RoomID]bool
|
JoinedRooms map[RoomID]bool
|
||||||
}
|
}
|
||||||
|
@ -240,4 +240,3 @@ func (a *Account) eventInternal(event *Event) error {
|
||||||
return mxSendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
|
return mxSendMessageAs(mx_room_id, typ, event.Text, mx_user_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@ package appservice
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/postgres"
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||||
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
|
@ -40,7 +40,7 @@ type DbUserMap struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
|
|
||||||
Protocol string
|
Protocol string
|
||||||
UserID connector.UserID
|
UserID connector.UserID
|
||||||
MxUserID string `gorm:"index:mxuserid"`
|
MxUserID string `gorm:"index:mxuserid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ type DbPmRoomMap struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
|
|
||||||
// User id and account name of the local end viewed on Matrix
|
// User id and account name of the local end viewed on Matrix
|
||||||
MxUserID string
|
MxUserID string
|
||||||
Protocol string
|
Protocol string
|
||||||
AccountName string
|
AccountName string
|
||||||
|
|
||||||
// User id to reach them
|
// User id to reach them
|
||||||
|
@ -83,7 +83,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
|
||||||
// If not create it
|
// If not create it
|
||||||
must_create := db.First(&room, DbRoomMap{
|
must_create := db.First(&room, DbRoomMap{
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
RoomID: roomId,
|
RoomID: roomId,
|
||||||
}).RecordNotFound()
|
}).RecordNotFound()
|
||||||
if must_create {
|
if must_create {
|
||||||
alias := roomAlias(protocol, roomId)
|
alias := roomAlias(protocol, roomId)
|
||||||
|
@ -103,7 +103,7 @@ func dbGetMxRoom(protocol string, roomId connector.RoomID) (string, error) {
|
||||||
|
|
||||||
room = DbRoomMap{
|
room = DbRoomMap{
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
RoomID: roomId,
|
RoomID: roomId,
|
||||||
MxRoomID: mx_room_id,
|
MxRoomID: mx_room_id,
|
||||||
}
|
}
|
||||||
db.Create(&room)
|
db.Create(&room)
|
||||||
|
@ -117,10 +117,10 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
|
||||||
var room DbPmRoomMap
|
var room DbPmRoomMap
|
||||||
|
|
||||||
must_create := db.First(&room, DbPmRoomMap{
|
must_create := db.First(&room, DbPmRoomMap{
|
||||||
MxUserID: usMxId,
|
MxUserID: usMxId,
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
AccountName: usAccount,
|
AccountName: usAccount,
|
||||||
UserID: them,
|
UserID: them,
|
||||||
}).RecordNotFound()
|
}).RecordNotFound()
|
||||||
if must_create {
|
if must_create {
|
||||||
name := fmt.Sprintf("%s (%s)", them, protocol)
|
name := fmt.Sprintf("%s (%s)", them, protocol)
|
||||||
|
@ -138,11 +138,11 @@ func dbGetMxPmRoom(protocol string, them connector.UserID, themMxId string, usMx
|
||||||
}
|
}
|
||||||
|
|
||||||
room = DbPmRoomMap{
|
room = DbPmRoomMap{
|
||||||
MxUserID: usMxId,
|
MxUserID: usMxId,
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
AccountName: usAccount,
|
AccountName: usAccount,
|
||||||
UserID: them,
|
UserID: them,
|
||||||
MxRoomID: mx_room_id,
|
MxRoomID: mx_room_id,
|
||||||
}
|
}
|
||||||
db.Create(&room)
|
db.Create(&room)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ func dbGetMxUser(protocol string, userId connector.UserID) (string, error) {
|
||||||
|
|
||||||
must_create := db.First(&user, DbUserMap{
|
must_create := db.First(&user, DbUserMap{
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
UserID: userId,
|
UserID: userId,
|
||||||
}).RecordNotFound()
|
}).RecordNotFound()
|
||||||
if must_create {
|
if must_create {
|
||||||
username := userMxId(protocol, userId)
|
username := userMxId(protocol, userId)
|
||||||
|
@ -174,7 +174,7 @@ func dbGetMxUser(protocol string, userId connector.UserID) (string, error) {
|
||||||
|
|
||||||
user = DbUserMap{
|
user = DbUserMap{
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
UserID: userId,
|
UserID: userId,
|
||||||
MxUserID: mxid,
|
MxUserID: mxid,
|
||||||
}
|
}
|
||||||
db.Create(&user)
|
db.Create(&user)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package appservice
|
package appservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func init() {
|
||||||
func mxGetApiCall(endpoint string, response interface{}) error {
|
func mxGetApiCall(endpoint string, response interface{}) error {
|
||||||
log.Debugf("Matrix GET request: %s\n", endpoint)
|
log.Debugf("Matrix GET request: %s\n", endpoint)
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", config.Server + endpoint, nil)
|
req, err := http.NewRequest("GET", config.Server+endpoint, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func mxPutApiCall(endpoint string, data interface{}, response interface{}) error
|
||||||
|
|
||||||
log.Debugf("Matrix PUT request: %s %s\n", endpoint, string(body))
|
log.Debugf("Matrix PUT request: %s %s\n", endpoint, string(body))
|
||||||
|
|
||||||
req, err := http.NewRequest("PUT", config.Server + endpoint, bytes.NewBuffer(body))
|
req, err := http.NewRequest("PUT", config.Server+endpoint, bytes.NewBuffer(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
|
||||||
|
|
||||||
log.Debugf("Matrix POST request: %s %s\n", endpoint, string(body))
|
log.Debugf("Matrix POST request: %s %s\n", endpoint, string(body))
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", config.Server + endpoint, bytes.NewBuffer(body))
|
req, err := http.NewRequest("POST", config.Server+endpoint, bytes.NewBuffer(body))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ func mxPostApiCall(endpoint string, data interface{}, response interface{}) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxDoAndParse(req *http.Request, response interface{}) error {
|
func mxDoAndParse(req *http.Request, response interface{}) error {
|
||||||
req.Header.Add("Authorization", "Bearer " + registration.AsToken)
|
req.Header.Add("Authorization", "Bearer "+registration.AsToken)
|
||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -125,7 +125,7 @@ func mxProfileDisplayname(userid string, displayname string) error {
|
||||||
|
|
||||||
func mxDirectoryRoom(alias string) (string, error) {
|
func mxDirectoryRoom(alias string) (string, error) {
|
||||||
var rep DirectoryRoomResponse
|
var rep DirectoryRoomResponse
|
||||||
err := mxGetApiCall("/_matrix/client/r0/directory/room/" + url.QueryEscape(alias), &rep)
|
err := mxGetApiCall("/_matrix/client/r0/directory/room/"+url.QueryEscape(alias), &rep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -134,18 +134,18 @@ func mxDirectoryRoom(alias string) (string, error) {
|
||||||
|
|
||||||
func mxCreateRoom(name string, alias string, invite []string) (string, error) {
|
func mxCreateRoom(name string, alias string, invite []string) (string, error) {
|
||||||
rq := CreateRoomRequest{
|
rq := CreateRoomRequest{
|
||||||
Preset: "private_chat",
|
Preset: "private_chat",
|
||||||
RoomAliasName: alias,
|
RoomAliasName: alias,
|
||||||
Name: name,
|
Name: name,
|
||||||
Topic: "",
|
Topic: "",
|
||||||
Invite: invite,
|
Invite: invite,
|
||||||
CreationContent: map[string]interface{} {
|
CreationContent: map[string]interface{}{
|
||||||
"m.federate": false,
|
"m.federate": false,
|
||||||
},
|
},
|
||||||
PowerLevels: map[string]interface{} {
|
PowerLevels: map[string]interface{}{
|
||||||
"invite": 100,
|
"invite": 100,
|
||||||
"events": map[string]interface{} {
|
"events": map[string]interface{}{
|
||||||
"m.room.topic": 0,
|
"m.room.topic": 0,
|
||||||
"m.room.avatar": 0,
|
"m.room.avatar": 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -161,19 +161,19 @@ func mxCreateRoom(name string, alias string, invite []string) (string, error) {
|
||||||
func mxCreateDirectRoomAs(name string, invite []string, as_user string) (string, error) {
|
func mxCreateDirectRoomAs(name string, invite []string, as_user string) (string, error) {
|
||||||
rq := CreateRoomNoAliasRequest{
|
rq := CreateRoomNoAliasRequest{
|
||||||
Preset: "private_chat",
|
Preset: "private_chat",
|
||||||
Name: name,
|
Name: name,
|
||||||
Topic: "",
|
Topic: "",
|
||||||
Invite: invite,
|
Invite: invite,
|
||||||
CreationContent: map[string]interface{} {
|
CreationContent: map[string]interface{}{
|
||||||
"m.federate": false,
|
"m.federate": false,
|
||||||
},
|
},
|
||||||
PowerLevels: map[string]interface{} {
|
PowerLevels: map[string]interface{}{
|
||||||
"invite": 100,
|
"invite": 100,
|
||||||
},
|
},
|
||||||
IsDirect: true,
|
IsDirect: true,
|
||||||
}
|
}
|
||||||
var rep CreateRoomResponse
|
var rep CreateRoomResponse
|
||||||
err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id=" + url.QueryEscape(as_user), &rq, &rep)
|
err := mxPostApiCall("/_matrix/client/r0/createRoom?user_id="+url.QueryEscape(as_user), &rq, &rep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ func mxRoomInvite(room string, user string) error {
|
||||||
UserId: user,
|
UserId: user,
|
||||||
}
|
}
|
||||||
var rep struct{}
|
var rep struct{}
|
||||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/invite", &rq, &rep)
|
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/invite", &rq, &rep)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,21 +195,21 @@ func mxRoomKick(room string, user string, reason string) error {
|
||||||
Reason: reason,
|
Reason: reason,
|
||||||
}
|
}
|
||||||
var rep struct{}
|
var rep struct{}
|
||||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/kick", &rq, &rep)
|
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/kick", &rq, &rep)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxRoomJoinAs(room string, user string) error {
|
func mxRoomJoinAs(room string, user string) error {
|
||||||
rq := struct{}{}
|
rq := struct{}{}
|
||||||
var rep RoomJoinResponse
|
var rep RoomJoinResponse
|
||||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/join?user_id=" + url.QueryEscape(user), &rq, &rep)
|
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/join?user_id="+url.QueryEscape(user), &rq, &rep)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxRoomLeaveAs(room string, user string) error {
|
func mxRoomLeaveAs(room string, user string) error {
|
||||||
rq := struct{}{}
|
rq := struct{}{}
|
||||||
var rep struct{}
|
var rep struct{}
|
||||||
err := mxPostApiCall("/_matrix/client/r0/rooms/" + url.QueryEscape(room) + "/leave?user_id=" + url.QueryEscape(user), &rq, &rep)
|
err := mxPostApiCall("/_matrix/client/r0/rooms/"+url.QueryEscape(room)+"/leave?user_id="+url.QueryEscape(user), &rq, &rep)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,9 +224,9 @@ func mxSendAs(room string, event_type string, content map[string]interface{}, us
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxSendMessageAs(room string, typ string, body string, user string) error {
|
func mxSendMessageAs(room string, typ string, body string, user string) error {
|
||||||
content := map[string]interface{} {
|
content := map[string]interface{}{
|
||||||
"msgtype": typ,
|
"msgtype": typ,
|
||||||
"body": body,
|
"body": body,
|
||||||
}
|
}
|
||||||
return mxSendAs(room, "m.room.message", content, user)
|
return mxSendAs(room, "m.room.message", content, user)
|
||||||
}
|
}
|
||||||
|
@ -241,14 +241,14 @@ func mxPutStateAs(room string, event_type string, key string, content map[string
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxRoomNameAs(room string, name string, as_user string) error {
|
func mxRoomNameAs(room string, name string, as_user string) error {
|
||||||
content := map[string]interface{} {
|
content := map[string]interface{}{
|
||||||
"name": name,
|
"name": name,
|
||||||
}
|
}
|
||||||
return mxPutStateAs(room, "m.room.name", "", content, as_user)
|
return mxPutStateAs(room, "m.room.name", "", content, as_user)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mxRoomTopicAs(room string, topic string, as_user string) error {
|
func mxRoomTopicAs(room string, topic string, as_user string) error {
|
||||||
content := map[string]interface{} {
|
content := map[string]interface{}{
|
||||||
"topic": topic,
|
"topic": topic,
|
||||||
}
|
}
|
||||||
return mxPutStateAs(room, "m.room.topic", "", content, as_user)
|
return mxPutStateAs(room, "m.room.topic", "", content, as_user)
|
||||||
|
|
|
@ -3,25 +3,24 @@ package appservice
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||||
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HttpBindAddr string
|
HttpBindAddr string
|
||||||
Server string
|
Server string
|
||||||
DbType string
|
DbType string
|
||||||
DbPath string
|
DbPath string
|
||||||
MatrixDomain string
|
MatrixDomain string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var registration *mxlib.Registration
|
var registration *mxlib.Registration
|
||||||
var config *Config
|
var config *Config
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,7 @@ type Handler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventType int
|
type EventType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EVENT_JOIN EventType = iota
|
EVENT_JOIN EventType = iota
|
||||||
EVENT_LEAVE
|
EVENT_LEAVE
|
||||||
|
@ -114,12 +115,12 @@ type Event struct {
|
||||||
|
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
DisplayName string
|
DisplayName string
|
||||||
Avatar MediaObject
|
Avatar MediaObject
|
||||||
}
|
}
|
||||||
|
|
||||||
type RoomInfo struct {
|
type RoomInfo struct {
|
||||||
Name string
|
Name string
|
||||||
Topic string
|
Topic string
|
||||||
Picture MediaObject
|
Picture MediaObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"fmt"
|
||||||
_ "os"
|
_ "os"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
"github.com/lrstanley/girc"
|
"github.com/lrstanley/girc"
|
||||||
|
|
||||||
|
@ -19,19 +19,19 @@ type IRC struct {
|
||||||
handler Handler
|
handler Handler
|
||||||
|
|
||||||
connected bool
|
connected bool
|
||||||
timeout int
|
timeout int
|
||||||
|
|
||||||
nick string
|
nick string
|
||||||
name string
|
name string
|
||||||
server string
|
server string
|
||||||
conn *girc.Client
|
conn *girc.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func (irc *IRC) SetHandler(h Handler) {
|
func (irc *IRC) SetHandler(h Handler) {
|
||||||
irc.handler = h
|
irc.handler = h
|
||||||
}
|
}
|
||||||
|
|
||||||
func(irc *IRC) Protocol() string {
|
func (irc *IRC) Protocol() string {
|
||||||
return "irc"
|
return "irc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,9 +64,9 @@ func (irc *IRC) Configure(c Configuration) error {
|
||||||
|
|
||||||
client := girc.New(girc.Config{
|
client := girc.New(girc.Config{
|
||||||
Server: irc.server,
|
Server: irc.server,
|
||||||
Port: port,
|
Port: port,
|
||||||
Nick: irc.nick,
|
Nick: irc.nick,
|
||||||
User: irc.nick,
|
User: irc.nick,
|
||||||
//Out: os.Stderr,
|
//Out: os.Stderr,
|
||||||
SSL: ssl,
|
SSL: ssl,
|
||||||
})
|
})
|
||||||
|
@ -85,7 +85,7 @@ func (irc *IRC) Configure(c Configuration) error {
|
||||||
go irc.connectLoop(client)
|
go irc.connectLoop(client)
|
||||||
|
|
||||||
for i := 0; i < 42; i++ {
|
for i := 0; i < 42; i++ {
|
||||||
time.Sleep(time.Duration(1)*time.Second)
|
time.Sleep(time.Duration(1) * time.Second)
|
||||||
if irc.conn != client {
|
if irc.conn != client {
|
||||||
break
|
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) {
|
func (irc *IRC) ircPrivmsg(c *girc.Client, e girc.Event) {
|
||||||
ev := &Event{
|
ev := &Event{
|
||||||
Type: EVENT_MESSAGE,
|
Type: EVENT_MESSAGE,
|
||||||
Author: UserID(e.Source.Name + "@" + irc.server),
|
Author: UserID(e.Source.Name + "@" + irc.server),
|
||||||
Text: e.Last(),
|
Text: e.Last(),
|
||||||
}
|
}
|
||||||
if e.IsFromChannel() {
|
if e.IsFromChannel() {
|
||||||
ev.Room = RoomID(e.Params[0] + "@" + irc.server)
|
ev.Room = RoomID(e.Params[0] + "@" + irc.server)
|
||||||
|
@ -265,9 +265,9 @@ func (irc *IRC) ircJoin(c *girc.Client, e girc.Event) {
|
||||||
} else {
|
} else {
|
||||||
user := UserID(e.Source.Name + "@" + irc.server)
|
user := UserID(e.Source.Name + "@" + irc.server)
|
||||||
ev := &Event{
|
ev := &Event{
|
||||||
Type: EVENT_JOIN,
|
Type: EVENT_JOIN,
|
||||||
Author: user,
|
Author: user,
|
||||||
Room: room,
|
Room: room,
|
||||||
}
|
}
|
||||||
irc.handler.Event(ev)
|
irc.handler.Event(ev)
|
||||||
irc.handler.UserInfoUpdated(user, &UserInfo{
|
irc.handler.UserInfoUpdated(user, &UserInfo{
|
||||||
|
@ -283,9 +283,9 @@ func (irc *IRC) ircPart(c *girc.Client, e girc.Event) {
|
||||||
} else {
|
} else {
|
||||||
user := UserID(e.Source.Name + "@" + irc.server)
|
user := UserID(e.Source.Name + "@" + irc.server)
|
||||||
ev := &Event{
|
ev := &Event{
|
||||||
Type: EVENT_LEAVE,
|
Type: EVENT_LEAVE,
|
||||||
Author: user,
|
Author: user,
|
||||||
Room: room,
|
Room: room,
|
||||||
}
|
}
|
||||||
irc.handler.Event(ev)
|
irc.handler.Event(ev)
|
||||||
irc.handler.UserInfoUpdated(user, &UserInfo{
|
irc.handler.UserInfoUpdated(user, &UserInfo{
|
||||||
|
@ -304,9 +304,9 @@ func (irc *IRC) ircNamreply(c *girc.Client, e girc.Event) {
|
||||||
src := girc.ParseSource(name)
|
src := girc.ParseSource(name)
|
||||||
if src.Name != irc.nick {
|
if src.Name != irc.nick {
|
||||||
irc.handler.Event(&Event{
|
irc.handler.Event(&Event{
|
||||||
Type: EVENT_JOIN,
|
Type: EVENT_JOIN,
|
||||||
Author: UserID(src.Name + "@" + irc.server),
|
Author: UserID(src.Name + "@" + irc.server),
|
||||||
Room: room,
|
Room: room,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
62
main.go
62
main.go
|
@ -1,41 +1,41 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
_ "fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
_"strings"
|
_ "strings"
|
||||||
_ "time"
|
_ "time"
|
||||||
_ "fmt"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/appservice"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/appservice"
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/irc"
|
||||||
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/connector/xmpp"
|
||||||
|
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConfigAccount struct {
|
type ConfigAccount struct {
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
Rooms []string `json:"rooms"`
|
Rooms []string `json:"rooms"`
|
||||||
Config map[string]string `json:"config"`
|
Config map[string]string `json:"config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConfigFile struct {
|
type ConfigFile struct {
|
||||||
HttpBindAddr string`json:"http_bind_addr"`
|
HttpBindAddr string `json:"http_bind_addr"`
|
||||||
Registration string `json:"registration"`
|
Registration string `json:"registration"`
|
||||||
Server string `json:"homeserver_url"`
|
Server string `json:"homeserver_url"`
|
||||||
DbType string `json:"db_type"`
|
DbType string `json:"db_type"`
|
||||||
DbPath string `json:"db_path"`
|
DbPath string `json:"db_path"`
|
||||||
MatrixDomain string `json:"matrix_domain"`
|
MatrixDomain string `json:"matrix_domain"`
|
||||||
Accounts map[string]map[string]ConfigAccount `json:"accounts"`
|
Accounts map[string]map[string]ConfigAccount `json:"accounts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var configFlag = flag.String("config", "./config.json", "Configuration file path")
|
var configFlag = flag.String("config", "./config.json", "Configuration file path")
|
||||||
|
@ -47,10 +47,10 @@ func readConfig() ConfigFile {
|
||||||
config_file := ConfigFile{
|
config_file := ConfigFile{
|
||||||
HttpBindAddr: "0.0.0.0:8321",
|
HttpBindAddr: "0.0.0.0:8321",
|
||||||
Registration: "./registration.yaml",
|
Registration: "./registration.yaml",
|
||||||
Server: "http://localhost:8008",
|
Server: "http://localhost:8008",
|
||||||
DbType: "sqlite3",
|
DbType: "sqlite3",
|
||||||
DbPath: "easybridge.db",
|
DbPath: "easybridge.db",
|
||||||
Accounts: map[string]map[string]ConfigAccount{},
|
Accounts: map[string]map[string]ConfigAccount{},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := os.Stat(*configFlag)
|
_, err := os.Stat(*configFlag)
|
||||||
|
@ -96,22 +96,22 @@ func readRegistration(file string) mxlib.Registration {
|
||||||
}
|
}
|
||||||
|
|
||||||
reg := mxlib.Registration{
|
reg := mxlib.Registration{
|
||||||
Id: "Easybridge",
|
Id: "Easybridge",
|
||||||
Url: "http://localhost:8321",
|
Url: "http://localhost:8321",
|
||||||
AsToken: hex.EncodeToString(rnd[:32]),
|
AsToken: hex.EncodeToString(rnd[:32]),
|
||||||
HsToken: hex.EncodeToString(rnd[32:]),
|
HsToken: hex.EncodeToString(rnd[32:]),
|
||||||
SenderLocalpart: "_ezbr_",
|
SenderLocalpart: "_ezbr_",
|
||||||
Namespaces: mxlib.RegistrationNamespaceSet{
|
Namespaces: mxlib.RegistrationNamespaceSet{
|
||||||
Users: []mxlib.RegistrationNamespace{
|
Users: []mxlib.RegistrationNamespace{
|
||||||
mxlib.RegistrationNamespace{
|
mxlib.RegistrationNamespace{
|
||||||
Exclusive: true,
|
Exclusive: true,
|
||||||
Regex: "@_ezbr_.*",
|
Regex: "@_ezbr_.*",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Aliases: []mxlib.RegistrationNamespace{
|
Aliases: []mxlib.RegistrationNamespace{
|
||||||
mxlib.RegistrationNamespace{
|
mxlib.RegistrationNamespace{
|
||||||
Exclusive: true,
|
Exclusive: true,
|
||||||
Regex: "#_ezbr_.*",
|
Regex: "#_ezbr_.*",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Rooms: []mxlib.RegistrationNamespace{},
|
Rooms: []mxlib.RegistrationNamespace{},
|
||||||
|
@ -166,9 +166,9 @@ func main() {
|
||||||
|
|
||||||
as_config := &appservice.Config{
|
as_config := &appservice.Config{
|
||||||
HttpBindAddr: config.HttpBindAddr,
|
HttpBindAddr: config.HttpBindAddr,
|
||||||
Server: config.Server,
|
Server: config.Server,
|
||||||
DbType: config.DbType,
|
DbType: config.DbType,
|
||||||
DbPath: config.DbPath,
|
DbPath: config.DbPath,
|
||||||
MatrixDomain: config.MatrixDomain,
|
MatrixDomain: config.MatrixDomain,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,10 +189,10 @@ func main() {
|
||||||
log.Fatalf("Invalid protocol %s", params.Protocol)
|
log.Fatalf("Invalid protocol %s", params.Protocol)
|
||||||
}
|
}
|
||||||
account := &appservice.Account{
|
account := &appservice.Account{
|
||||||
MatrixUser: fmt.Sprintf("@%s:%s", user, config.MatrixDomain),
|
MatrixUser: fmt.Sprintf("@%s:%s", user, config.MatrixDomain),
|
||||||
AccountName: name,
|
AccountName: name,
|
||||||
Protocol: params.Protocol,
|
Protocol: params.Protocol,
|
||||||
Conn: conn,
|
Conn: conn,
|
||||||
JoinedRooms: map[connector.RoomID]bool{},
|
JoinedRooms: map[connector.RoomID]bool{},
|
||||||
}
|
}
|
||||||
conn.SetHandler(account)
|
conn.SetHandler(account)
|
||||||
|
|
45
mxlib/api.go
45
mxlib/api.go
|
@ -6,7 +6,7 @@ import (
|
||||||
|
|
||||||
type MxError struct {
|
type MxError struct {
|
||||||
ErrCode string `json:"errcode"`
|
ErrCode string `json:"errcode"`
|
||||||
ErrMsg string `json:"error"`
|
ErrMsg string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *MxError) Error() string {
|
func (e *MxError) Error() string {
|
||||||
|
@ -18,12 +18,12 @@ type Transaction struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Content map[string]interface{} `json:"content"`
|
Content map[string]interface{} `json:"content"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
EventId string `json:"event_id"`
|
EventId string `json:"event_id"`
|
||||||
RoomId string `json:"room_id"`
|
RoomId string `json:"room_id"`
|
||||||
Sender string `json:"sender"`
|
Sender string `json:"sender"`
|
||||||
OriginServerTs int `json:"origin_server_ts"`
|
OriginServerTs int `json:"origin_server_ts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegisterRequest struct {
|
type RegisterRequest struct {
|
||||||
|
@ -31,9 +31,9 @@ type RegisterRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegisterResponse struct {
|
type RegisterResponse struct {
|
||||||
UserId string `json:"user_id"`
|
UserId string `json:"user_id"`
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
DeviceId string `json:"device_id"`
|
DeviceId string `json:"device_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProfileDisplaynameRequest struct {
|
type ProfileDisplaynameRequest struct {
|
||||||
|
@ -41,23 +41,23 @@ type ProfileDisplaynameRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRoomRequest struct {
|
type CreateRoomRequest struct {
|
||||||
Preset string `json:"preset"`
|
Preset string `json:"preset"`
|
||||||
RoomAliasName string `json:"room_alias_name"`
|
RoomAliasName string `json:"room_alias_name"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Topic string `json:"topic"`
|
Topic string `json:"topic"`
|
||||||
Invite []string `json:"invite"`
|
Invite []string `json:"invite"`
|
||||||
CreationContent map[string]interface{} `json:"creation_content"`
|
CreationContent map[string]interface{} `json:"creation_content"`
|
||||||
PowerLevels map[string]interface{} `json:"power_level_content_override"`
|
PowerLevels map[string]interface{} `json:"power_level_content_override"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRoomNoAliasRequest struct {
|
type CreateRoomNoAliasRequest struct {
|
||||||
Preset string `json:"preset"`
|
Preset string `json:"preset"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Topic string `json:"topic"`
|
Topic string `json:"topic"`
|
||||||
Invite []string `json:"invite"`
|
Invite []string `json:"invite"`
|
||||||
CreationContent map[string]interface{} `json:"creation_content"`
|
CreationContent map[string]interface{} `json:"creation_content"`
|
||||||
PowerLevels map[string]interface{} `json:"power_level_content_override"`
|
PowerLevels map[string]interface{} `json:"power_level_content_override"`
|
||||||
IsDirect bool `json:"is_direct"`
|
IsDirect bool `json:"is_direct"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateRoomResponse struct {
|
type CreateRoomResponse struct {
|
||||||
|
@ -65,7 +65,7 @@ type CreateRoomResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DirectoryRoomResponse struct {
|
type DirectoryRoomResponse struct {
|
||||||
RoomId string `json:"room_id"`
|
RoomId string `json:"room_id"`
|
||||||
Servers []string `json:"string"`
|
Servers []string `json:"string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,4 +84,3 @@ type RoomJoinResponse struct {
|
||||||
type RoomSendResponse struct {
|
type RoomSendResponse struct {
|
||||||
EventId string `json:"event_id"`
|
EventId string `json:"event_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,21 +5,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Registration struct {
|
type Registration struct {
|
||||||
Id string `yaml:"id"`
|
Id string `yaml:"id"`
|
||||||
Url string `yaml:"url"`
|
Url string `yaml:"url"`
|
||||||
AsToken string `yaml:"as_token"`
|
AsToken string `yaml:"as_token"`
|
||||||
HsToken string `yaml:"hs_token"`
|
HsToken string `yaml:"hs_token"`
|
||||||
SenderLocalpart string `yaml:"sender_localpart"`
|
SenderLocalpart string `yaml:"sender_localpart"`
|
||||||
Namespaces RegistrationNamespaceSet `yaml:"namespaces"`
|
Namespaces RegistrationNamespaceSet `yaml:"namespaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegistrationNamespaceSet struct {
|
type RegistrationNamespaceSet struct {
|
||||||
Users []RegistrationNamespace `yaml:"users"`
|
Users []RegistrationNamespace `yaml:"users"`
|
||||||
Aliases []RegistrationNamespace `yaml:"aliases"`
|
Aliases []RegistrationNamespace `yaml:"aliases"`
|
||||||
Rooms []RegistrationNamespace `yaml:"rooms"`
|
Rooms []RegistrationNamespace `yaml:"rooms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RegistrationNamespace struct {
|
type RegistrationNamespace struct {
|
||||||
Exclusive bool `yaml:"exclusive"`
|
Exclusive bool `yaml:"exclusive"`
|
||||||
Regex string `yaml:"regex"`
|
Regex string `yaml:"regex"`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue