Rename package, bump Go to 1.22

This commit is contained in:
Jarno Rankinen 2024-03-24 14:22:00 +02:00
parent 2e905544ae
commit f3f6b8e23f
18 changed files with 75 additions and 69 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
__debug_bin*
config.yaml
registration.yaml
logs/
matrix-skype.db

View File

@ -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.")

View File

@ -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"`

View File

@ -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{

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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"
)

View File

@ -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"
)

View File

@ -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("<at[^>]+\\bid=\"([^\"]+)\"(.*?)</at>*")
type Formatter struct {
@ -81,8 +81,7 @@ func NewFormatter(bridge *Bridge) *Formatter {
return fmt.Sprintf("<code>%s</code>", 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 '<a><a/>' tag
reg:= regexp.MustCompile(`(?U)(<a .*>(.*)</a>)`)
reg := regexp.MustCompile(`(?U)(<a .*>(.*)</a>)`)
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

View File

@ -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"

6
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

10
main.go
View File

@ -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()

View File

@ -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)

View File

@ -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 {
@ -411,10 +411,10 @@ func (portal *Portal) SyncParticipants(user *User, metadata *skypeExt.GroupInfo)
// 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.
// 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)
@ -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.")
}
}

View File

@ -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

12
user.go
View File

@ -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))