diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b7385b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +__debug_bin* +config.yaml +registration.yaml +logs/ +matrix-skype.db diff --git a/commands.go b/commands.go index 29d796e..a24975e 100644 --- a/commands.go +++ b/commands.go @@ -5,9 +5,9 @@ import ( "fmt" "math" + "github.com/0ranki/matrix-skype/database" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" skype "github.com/kelaresg/go-skypeapi" - "github.com/kelaresg/matrix-skype/database" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" "maunium.net/go/mautrix/patch" "sort" @@ -388,8 +388,8 @@ func (handler *CommandHandler) CommandPing(ce *CommandEvent) { } ce.Reply("You're logged in as @" + username + ", orgid is " + orgId) } - var password string; - var username string; + var password string + var username string ret := ce.User.bridge.DB.User.GetCredentialsByMXID(ce.User.MXID, &password, &username) if ret && password != "" { ce.Reply("WARNING, your password is stored in database. Use command `remove-password` to remove it.") diff --git a/config/bridge.go b/config/bridge.go index 1ae7842..780a4d6 100644 --- a/config/bridge.go +++ b/config/bridge.go @@ -11,7 +11,7 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" ) type BridgeConfig struct { @@ -42,7 +42,7 @@ type BridgeConfig struct { SyncChatMaxAge uint64 `yaml:"sync_max_chat_age"` SyncContact bool `yaml:"sync_contact"` - SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"` + SyncWithCustomPuppets bool `yaml:"sync_with_custom_puppets"` InviteOwnPuppetForBackfilling bool `yaml:"invite_own_puppet_for_backfilling"` PrivateChatPortalMeta bool `yaml:"private_chat_portal_meta"` @@ -68,7 +68,7 @@ type BridgeConfig struct { } `yaml:"key_sharing"` PuppetId struct { - Allow bool `yaml:"allow"` + Allow bool `yaml:"allow"` Key string `yaml:"key"` UsernameTemplatePrefix string `yaml:"username_template_prefix"` } `yaml:"puppet_id"` diff --git a/crypto.go b/crypto.go index 4718d74..8a8ad0e 100644 --- a/crypto.go +++ b/crypto.go @@ -30,7 +30,7 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/database" + "github.com/0ranki/matrix-skype/database" ) var levelTrace = maulogger.Level{ diff --git a/database/database.go b/database/database.go index b217ae4..f432d6c 100644 --- a/database/database.go +++ b/database/database.go @@ -24,7 +24,7 @@ import ( log "maunium.net/go/maulogger/v2" - "github.com/kelaresg/matrix-skype/database/upgrades" + "github.com/0ranki/matrix-skype/database/upgrades" ) type Database struct { diff --git a/database/message.go b/database/message.go index 528629b..273f7c0 100644 --- a/database/message.go +++ b/database/message.go @@ -6,7 +6,7 @@ import ( "encoding/json" log "maunium.net/go/maulogger/v2" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" "maunium.net/go/mautrix/id" ) @@ -35,27 +35,27 @@ func (mq *MessageQuery) GetAll(chat PortalKey) (messages []*Message) { } func (mq *MessageQuery) GetByJID(chat PortalKey, jid types.SkypeMessageID) *Message { - return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+ "FROM message WHERE chat_jid=$1 AND jid=$2", chat.JID, jid) } func (mq *MessageQuery) oldGetByJID(chat PortalKey, jid types.SkypeMessageID) *Message { - return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+ "FROM message WHERE chat_jid=$1 AND chat_receiver=$2 AND jid=$3", chat.JID, chat.Receiver, jid) } func (mq *MessageQuery) GetByMXID(mxid id.EventID) *Message { - return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+ "FROM message WHERE mxid=$1", mxid) } func (mq *MessageQuery) GetByID(id string) *Message { - return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + + return mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+ "FROM message WHERE id=$1", id) } func (mq *MessageQuery) GetLastInChat(chat PortalKey) *Message { - msg := mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content " + + msg := mq.get("SELECT id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content "+ "FROM message WHERE chat_jid=$1 AND chat_receiver=$2 ORDER BY timestamp DESC LIMIT 1", chat.JID, chat.Receiver) if msg == nil || msg.Timestamp == 0 { // Old db, we don't know what the last message is. @@ -122,7 +122,7 @@ func (msg *Message) encodeBinaryContent() []byte { } func (msg *Message) Insert() { - _, err := msg.db.Exec("INSERT INTO message (id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content) " + + _, err := msg.db.Exec("INSERT INTO message (id, chat_jid, chat_receiver, jid, mxid, sender, timestamp, content) "+ "VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", msg.ID, msg.Chat.JID, msg.Chat.Receiver, msg.JID, msg.MXID, msg.Sender, msg.Timestamp, msg.encodeBinaryContent()) if err != nil { diff --git a/database/portal.go b/database/portal.go index ade1cba..5dea42d 100644 --- a/database/portal.go +++ b/database/portal.go @@ -2,14 +2,14 @@ package database import ( "database/sql" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" "strings" log "maunium.net/go/maulogger/v2" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" ) type PortalKey struct { diff --git a/database/puppet.go b/database/puppet.go index b21db69..ecbb95c 100644 --- a/database/puppet.go +++ b/database/puppet.go @@ -5,7 +5,7 @@ import ( log "maunium.net/go/maulogger/v2" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" "maunium.net/go/mautrix/id" ) diff --git a/database/user.go b/database/user.go index 5673af3..1fa75f4 100644 --- a/database/user.go +++ b/database/user.go @@ -3,14 +3,14 @@ package database import ( "database/sql" "fmt" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" skype "github.com/kelaresg/go-skypeapi" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" "strings" "time" log "maunium.net/go/maulogger/v2" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" "maunium.net/go/mautrix/id" ) diff --git a/formatting.go b/formatting.go index 6b51c25..dd9ee7d 100644 --- a/formatting.go +++ b/formatting.go @@ -6,13 +6,13 @@ import ( "regexp" "strings" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/format" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/types" ) var italicRegex = regexp.MustCompile("([\\s>~*]|^)_(.+?)_([^a-zA-Z\\d]|$)") @@ -20,8 +20,8 @@ var boldRegex = regexp.MustCompile("([\\s>_~]|^)\\*(.+?)\\*([^a-zA-Z\\d]|$)") var strikethroughRegex = regexp.MustCompile("([\\s>_*]|^)~(.+?)~([^a-zA-Z\\d]|$)") var codeBlockRegex = regexp.MustCompile("```(?:.|\n)+?```") -//var mentionRegex = regexp.MustCompile("@[0-9]+") -//var mentionRegex = regexp.MustCompile("@(.*)") +// var mentionRegex = regexp.MustCompile("@[0-9]+") +// var mentionRegex = regexp.MustCompile("@(.*)") var mentionRegex = regexp.MustCompile("]+\\bid=\"([^\"]+)\"(.*?)*") type Formatter struct { @@ -81,8 +81,7 @@ func NewFormatter(bridge *Bridge) *Formatter { return fmt.Sprintf("%s", str) }, } - formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{ - } + formatter.waReplFuncText = map[*regexp.Regexp]func(string) string{} return formatter } @@ -99,7 +98,7 @@ func (formatter *Formatter) getMatrixInfoByJID(jid types.SkypeID) (mxid id.UserI func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomMXID id.RoomID) { // parse '' tag - reg:= regexp.MustCompile(`(?U)((.*))`) + reg := regexp.MustCompile(`(?U)((.*))`) bodyMatch := reg.FindAllStringSubmatch(content.Body, -1) for _, match := range bodyMatch { content.Body = strings.ReplaceAll(content.Body, match[1], match[2]) @@ -139,7 +138,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM content.Body = fmt.Sprintf("%s\n\n", match[6]) // this means that there are forwarding messages across groups - if strings.HasSuffix(match[4], skypeExt.GroupSuffix) || strings.HasSuffix(portal.Key.JID, skypeExt.GroupSuffix){ + if strings.HasSuffix(match[4], skypeExt.GroupSuffix) || strings.HasSuffix(portal.Key.JID, skypeExt.GroupSuffix) { continue } } @@ -159,7 +158,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM content.FormattedBody = newContent content.Body = fmt.Sprintf("> <%s> %s\n\n", mxid, match[6]) inRelateTo := &event.RelatesTo{ - Type: event.RelReply, + Type: event.RelReply, EventID: id.EventID(msgMXID), } content.SetRelatesTo(inRelateTo) @@ -190,7 +189,7 @@ func (formatter *Formatter) ParseSkype(content *event.MessageEventContent, RoomM } // number := "@" + strings.Replace(match[1], skypeExt.NewUserSuffix, "", 1) originStr = strings.ReplaceAll(originStr, match[0], replaceStr) - originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname + ":") + originBodyStr = strings.ReplaceAll(originStr, replaceStr, displayname+":") } if len(backStr) == 0 { content.Format = event.FormatHTML diff --git a/formatting_test.go b/formatting_test.go index 472fa2c..7c12e06 100644 --- a/formatting_test.go +++ b/formatting_test.go @@ -1,8 +1,8 @@ package main import ( - "github.com/kelaresg/matrix-skype/database" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/database" + "github.com/0ranki/matrix-skype/types" "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/format" "reflect" diff --git a/go.mod b/go.mod index 0c9f5eb..f411cf6 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ -module github.com/kelaresg/matrix-skype +module github.com/0ranki/matrix-skype -go 1.18 +go 1.22 require ( github.com/gabriel-vasile/mimetype v1.1.2 github.com/gorilla/websocket v1.4.2 github.com/kelaresg/go-skypeapi v0.1.2-0.20210813144457-5bc29092a74e github.com/lib/pq v1.9.0 - github.com/mattn/go-sqlite3 v2.0.3+incompatible + github.com/mattn/go-sqlite3 v1.14.22 github.com/pkg/errors v0.9.1 gopkg.in/yaml.v2 v2.4.0 maunium.net/go/mauflag v1.0.0 diff --git a/go.sum b/go.sum index 375dbff..2eef008 100644 --- a/go.sum +++ b/go.sum @@ -151,6 +151,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U= github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= diff --git a/main.go b/main.go index fcc4f72..818ead2 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,10 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/config" - "github.com/kelaresg/matrix-skype/database" - "github.com/kelaresg/matrix-skype/database/upgrades" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/config" + "github.com/0ranki/matrix-skype/database" + "github.com/0ranki/matrix-skype/database/upgrades" + "github.com/0ranki/matrix-skype/types" ) var ( @@ -48,7 +48,7 @@ func init() { var configPath = flag.MakeFull("c", "config", "The path to your config file.", "config.yaml").String() -//var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String() +// var baseConfigPath = flag.MakeFull("b", "base-config", "The path to the example config file.", "example-config.yaml").String() var registrationPath = flag.MakeFull("r", "registration", "The path where to save the appservice registration.", "registration.yaml").String() var generateRegistration = flag.MakeFull("g", "generate-registration", "Generate registration and quit.", "false").Bool() var version = flag.MakeFull("v", "version", "View bridge version and quit.", "false").Bool() diff --git a/matrix.go b/matrix.go index 4794644..df44ab4 100644 --- a/matrix.go +++ b/matrix.go @@ -6,8 +6,8 @@ import ( "strings" "time" + "github.com/0ranki/matrix-skype/database" skype "github.com/kelaresg/go-skypeapi" - "github.com/kelaresg/matrix-skype/database" "maunium.net/go/mautrix" "maunium.net/go/mautrix/patch" @@ -398,7 +398,7 @@ func (mx *MatrixHandler) HandleMessage(evt *event.Event) { } if hasCommandPrefix || evt.RoomID == user.ManagementRoom { mx.cmd.Handle(evt.RoomID, user, content.Body) - if strings.HasPrefix(content.Body, "login") == true { + if strings.HasPrefix(content.Body, "login") == true { go func() { time.Sleep(time.Second * 10) customPuppet := user.bridge.GetPuppetByJID(user.JID) diff --git a/portal.go b/portal.go index d896902..5913a44 100644 --- a/portal.go +++ b/portal.go @@ -23,8 +23,8 @@ import ( "sync" "time" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" skype "github.com/kelaresg/go-skypeapi" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" "github.com/pkg/errors" log "maunium.net/go/maulogger/v2" @@ -36,8 +36,8 @@ import ( "maunium.net/go/mautrix/id" "maunium.net/go/mautrix/pushrules" - "github.com/kelaresg/matrix-skype/database" - "github.com/kelaresg/matrix-skype/types" + "github.com/0ranki/matrix-skype/database" + "github.com/0ranki/matrix-skype/types" ) func (bridge *Bridge) GetPortalByMXID(mxid id.RoomID) *Portal { @@ -409,13 +409,13 @@ func (portal *Portal) SyncParticipants(user *User, metadata *skypeExt.GroupInfo) for _, participant := range metadata.Participants { portal.log.Debugln("SyncParticipants: participant.JID= ", participant.JID) - // When synchronizing Skype room members, first look up whether there is a corresponding record in the user table. + // When synchronizing Skype room members, first look up whether there is a corresponding record in the user table. // If there is, there are two possibilities: - // 1. This member is the puppet of the skype account A that you are currently importing, + // 1. This member is the puppet of the skype account A that you are currently importing, // and has a corresponding matrix account - // 2. This member is a puppet of other people's skype account B. - // the other people have registered a matrix account in the same matrix server + // 2. This member is a puppet of other people's skype account B. + // the other people have registered a matrix account in the same matrix server // and have also synchronized (bridged) skype account B. skype A and skype B are in the same skype room. participantUser := portal.bridge.GetUserByJID(participant.JID) if participantUser != nil { @@ -614,7 +614,7 @@ func (portal *Portal) userMXIDAction(user *User, fn func(mxid id.UserID)) { } func (portal *Portal) ensureMXIDInvited(mxid id.UserID) { - portal.log.Debugfln("ensureMXIDInvited portal.MXID %s: %s", portal.MXID, mxid); + portal.log.Debugfln("ensureMXIDInvited portal.MXID %s: %s", portal.MXID, mxid) err := portal.MainIntent().EnsureInvited(portal.MXID, mxid) if err != nil { portal.log.Warnfln("Failed to ensure %s is invited to %s: %v", mxid, portal.MXID, err) @@ -1152,7 +1152,7 @@ func (portal *Portal) CreateMatrixRoom(user *User) error { portal.Name = portalName } else { portal.Name = metadata.Name - if (user.currentCreateRoomName == portal.Name && portal.Name != "") { + if user.currentCreateRoomName == portal.Name && portal.Name != "" { return errors.New("It looks like a room is being created in the matrix using command 'create', so there is no need to create a new room here.") } } diff --git a/puppet.go b/puppet.go index 7da4fc4..3e2649b 100644 --- a/puppet.go +++ b/puppet.go @@ -2,21 +2,21 @@ package main import ( "fmt" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" skype "github.com/kelaresg/go-skypeapi" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" "net/http" "regexp" - "sync" "strings" + "sync" log "maunium.net/go/maulogger/v2" "maunium.net/go/mautrix/appservice" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/database" - "github.com/kelaresg/matrix-skype/types" - //"github.com/kelaresg/matrix-skype/whatsapp-ext" + "github.com/0ranki/matrix-skype/database" + "github.com/0ranki/matrix-skype/types" + //"github.com/0ranki/matrix-skype/whatsapp-ext" ) func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.SkypeID, bool) { @@ -36,7 +36,7 @@ func (bridge *Bridge) ParsePuppetMXID(mxid id.UserID) (types.SkypeID, bool) { cond2 := "8-" if strings.HasPrefix(realId, cond1) { realId = strings.Replace(realId, cond1, "8:live:", 1) - } else if strings.HasPrefix(realId, cond2){ + } else if strings.HasPrefix(realId, cond2) { realId = strings.Replace(realId, cond2, "8:", 1) } jid := types.SkypeID(realId + skypeExt.NewUserSuffix) @@ -140,8 +140,8 @@ func (bridge *Bridge) NewPuppet(dbPuppet *database.Puppet) *Puppet { ":", "-", -1, - ), ), + ), bridge.Config.Homeserver.Domain), } } @@ -172,13 +172,13 @@ func (puppet *Puppet) IntentFor(portal *Portal) *appservice.IntentAPI { puppet.log.Debugln("puppent IntentFor: %+v", puppet) if (!portal.IsPrivateChat() && puppet.customIntent == nil) || (portal.backfilling && portal.bridge.Config.Bridge.InviteOwnPuppetForBackfilling) || - portal.Key.JID + skypeExt.NewUserSuffix == puppet.JID { + portal.Key.JID+skypeExt.NewUserSuffix == puppet.JID { puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID) puppet.log.Debugln("puppent IntentFor0:", portal.Key.JID, puppet.JID) return puppet.DefaultIntent() } puppet.log.Debugln("puppent IntentFor2: %+v", puppet.customIntent) - if portal.IsPrivateChat() && puppet.customIntent == nil{ + if portal.IsPrivateChat() && puppet.customIntent == nil { return puppet.DefaultIntent() } return puppet.customIntent @@ -309,8 +309,8 @@ func (puppet *Puppet) Sync(source *User, contact skype.Contact) { // contact.Notify = source.Conn.Info.Pushname //} avatar := &skypeExt.ProfilePicInfo{ - URL: contact.Profile.AvatarUrl, - Tag: contact.Profile.AvatarUrl, + URL: contact.Profile.AvatarUrl, + Tag: contact.Profile.AvatarUrl, Status: 0, } update := false diff --git a/user.go b/user.go index e380e26..a9086bc 100644 --- a/user.go +++ b/user.go @@ -7,8 +7,8 @@ import ( "fmt" "sort" + skypeExt "github.com/0ranki/matrix-skype/skype-ext" skype "github.com/kelaresg/go-skypeapi" - skypeExt "github.com/kelaresg/matrix-skype/skype-ext" "maunium.net/go/mautrix/patch" //"strconv" @@ -25,9 +25,9 @@ import ( "maunium.net/go/mautrix/event" "maunium.net/go/mautrix/id" - "github.com/kelaresg/matrix-skype/database" - "github.com/kelaresg/matrix-skype/types" - //"github.com/kelaresg/matrix-skype/whatsapp-ext" + "github.com/0ranki/matrix-skype/database" + "github.com/0ranki/matrix-skype/types" + //"github.com/0ranki/matrix-skype/whatsapp-ext" ) type User struct { @@ -56,7 +56,7 @@ type User struct { mgmtCreateLock sync.Mutex - contactsPresence map[string]*skypeExt.Presence + contactsPresence map[string]*skypeExt.Presence currentCreateRoomName string } @@ -657,7 +657,7 @@ func (user *User) syncPuppets(contacts map[string]skype.Contact, toHomeserver bo user.log.Infoln("Syncing puppet info from contacts", personId, skypeExt.NewUserSuffix) if strings.HasSuffix(personId, skypeExt.NewUserSuffix) { puppet := user.bridge.GetPuppetByJID(personId) - if (!toHomeserver) { + if !toHomeserver { puppet.Sync(user, contact) } matrixContacts = append(matrixContacts, string(puppet.MXID))