Fix %!(MISSING) and other formatting issues
This commit is contained in:
parent
ad6e92e6d6
commit
f2f20e680b
4
go.mod
4
go.mod
|
@ -10,8 +10,8 @@ require (
|
||||||
github.com/soheilhy/args v0.0.0-20150720134047-6bcf4c78e87e
|
github.com/soheilhy/args v0.0.0-20150720134047-6bcf4c78e87e
|
||||||
github.com/zelenin/go-tdlib v0.1.0
|
github.com/zelenin/go-tdlib v0.1.0
|
||||||
gopkg.in/yaml.v2 v2.2.4
|
gopkg.in/yaml.v2 v2.2.4
|
||||||
gosrc.io/xmpp v0.1.3
|
gosrc.io/xmpp v0.5.2-0.20211214110136-5f99e1cd06e1
|
||||||
)
|
)
|
||||||
|
|
||||||
replace gosrc.io/xmpp => github.com/bodqhrohro/go-xmpp v0.1.4-0.20191106203535-f3b463f3b26c
|
replace gosrc.io/xmpp => github.com/bodqhrohro/go-xmpp v0.2.1-0.20211218153313-a8aadd78b65b
|
||||||
replace github.com/zelenin/go-tdlib => github.com/godcong/go-tdlib v0.4.4-0.20211203152853-64d22ab8d4ac
|
replace github.com/zelenin/go-tdlib => github.com/godcong/go-tdlib v0.4.4-0.20211203152853-64d22ab8d4ac
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -10,6 +10,10 @@ github.com/bodqhrohro/go-xmpp v0.1.4-0.20191106203535-f3b463f3b26c h1:LzcQyE+Gs+
|
||||||
github.com/bodqhrohro/go-xmpp v0.1.4-0.20191106203535-f3b463f3b26c/go.mod h1:fWixaMaFvx8cxXcJVJ5kU9csMeD/JN8on7ybassU8rY=
|
github.com/bodqhrohro/go-xmpp v0.1.4-0.20191106203535-f3b463f3b26c/go.mod h1:fWixaMaFvx8cxXcJVJ5kU9csMeD/JN8on7ybassU8rY=
|
||||||
github.com/bodqhrohro/go-xmpp v0.2.1-0.20191105232737-9abd5be0aa1b h1:9BLd/SNO4JJZLRl1Qb1v9mNivIlHuwHDe2c8hQvBxFA=
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20191105232737-9abd5be0aa1b h1:9BLd/SNO4JJZLRl1Qb1v9mNivIlHuwHDe2c8hQvBxFA=
|
||||||
github.com/bodqhrohro/go-xmpp v0.2.1-0.20191105232737-9abd5be0aa1b/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20191105232737-9abd5be0aa1b/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||||
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20211205194122-f8c4ecb59d8b h1:rTK55SNCBmssyRgNAweVwVVfuoRstI8RbL+8Ys/RzxE=
|
||||||
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20211205194122-f8c4ecb59d8b/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||||
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20211218153313-a8aadd78b65b h1:VDi8z3PzEDhQzazRRuv1fkv662DT3Mm/TY/Lni2Sgrc=
|
||||||
|
github.com/bodqhrohro/go-xmpp v0.2.1-0.20211218153313-a8aadd78b65b/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||||
github.com/chromedp/cdproto v0.0.0-20190614062957-d6d2f92b486d/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw=
|
github.com/chromedp/cdproto v0.0.0-20190614062957-d6d2f92b486d/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw=
|
||||||
github.com/chromedp/cdproto v0.0.0-20190621002710-8cbd498dd7a0/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw=
|
github.com/chromedp/cdproto v0.0.0-20190621002710-8cbd498dd7a0/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw=
|
||||||
github.com/chromedp/cdproto v0.0.0-20190812224334-39ef923dcb8d/go.mod h1:0YChpVzuLJC5CPr+x3xkHN6Z8KOSXjNbL7qV8Wc4GW0=
|
github.com/chromedp/cdproto v0.0.0-20190812224334-39ef923dcb8d/go.mod h1:0YChpVzuLJC5CPr+x3xkHN6Z8KOSXjNbL7qV8Wc4GW0=
|
||||||
|
@ -126,6 +130,8 @@ gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gosrc.io/xmpp v0.1.3 h1:VYP1bA35irlQ1ZAJqNhJOz8NSsSTkzQRhREfmuG1H80=
|
gosrc.io/xmpp v0.1.3 h1:VYP1bA35irlQ1ZAJqNhJOz8NSsSTkzQRhREfmuG1H80=
|
||||||
gosrc.io/xmpp v0.1.3/go.mod h1:fWixaMaFvx8cxXcJVJ5kU9csMeD/JN8on7ybassU8rY=
|
gosrc.io/xmpp v0.1.3/go.mod h1:fWixaMaFvx8cxXcJVJ5kU9csMeD/JN8on7ybassU8rY=
|
||||||
|
gosrc.io/xmpp v0.5.2-0.20211214110136-5f99e1cd06e1 h1:E3uJqX6ImJL9AFdjGbiW04jq8IQ+NcOK+JSiWq2TbRw=
|
||||||
|
gosrc.io/xmpp v0.5.2-0.20211214110136-5f99e1cd06e1/go.mod h1:L3NFMqYOxyLz3JGmgFyWf7r9htE91zVGiK40oW4RwdY=
|
||||||
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
gotest.tools v2.1.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||||
gotest.tools/gotestsum v0.3.5/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
|
gotest.tools/gotestsum v0.3.5/go.mod h1:Mnf3e5FUzXbkCfynWBGOwLssY7gTQgCHObK9tMpAriY=
|
||||||
mvdan.cc/sh v2.6.4+incompatible/go.mod h1:IeeQbZq+x2SUGBensq/jge5lLQbS3XT2ktyp3wrt4x8=
|
mvdan.cc/sh v2.6.4+incompatible/go.mod h1:IeeQbZq+x2SUGBensq/jge5lLQbS3XT2ktyp3wrt4x8=
|
||||||
|
|
|
@ -17,10 +17,10 @@ type Insertion struct {
|
||||||
// from the start or from the end
|
// from the start or from the end
|
||||||
type InsertionStack []*Insertion
|
type InsertionStack []*Insertion
|
||||||
|
|
||||||
var boldRunes = []rune("**")
|
var boldRunesMarkdown = []rune("**")
|
||||||
|
var boldRunesXEP0393 = []rune("*")
|
||||||
var italicRunes = []rune("_")
|
var italicRunes = []rune("_")
|
||||||
var codeRunes = []rune("\n```\n")
|
var codeRunes = []rune("\n```\n")
|
||||||
var urlRuneL = []rune("[")
|
|
||||||
|
|
||||||
// rebalance pumps all the values at given offset to current stack (growing
|
// rebalance pumps all the values at given offset to current stack (growing
|
||||||
// from start) from given stack (growing from end); should be called
|
// from start) from given stack (growing from end); should be called
|
||||||
|
@ -80,7 +80,7 @@ func markupBraces(entity *client.TextEntity, lbrace, rbrace []rune) (*Insertion,
|
||||||
func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) {
|
func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) {
|
||||||
switch entity.Type.TextEntityTypeType() {
|
switch entity.Type.TextEntityTypeType() {
|
||||||
case client.TypeTextEntityTypeBold:
|
case client.TypeTextEntityTypeBold:
|
||||||
return markupBraces(entity, boldRunes, boldRunes)
|
return markupBraces(entity, boldRunesMarkdown, boldRunesMarkdown)
|
||||||
case client.TypeTextEntityTypeItalic:
|
case client.TypeTextEntityTypeItalic:
|
||||||
return markupBraces(entity, italicRunes, italicRunes)
|
return markupBraces(entity, italicRunes, italicRunes)
|
||||||
case client.TypeTextEntityTypeCode, client.TypeTextEntityTypePre:
|
case client.TypeTextEntityTypeCode, client.TypeTextEntityTypePre:
|
||||||
|
@ -90,13 +90,35 @@ func EntityToMarkdown(entity *client.TextEntity) (*Insertion, *Insertion) {
|
||||||
return markupBraces(entity, []rune("\n```"+preCode.Language+"\n"), codeRunes)
|
return markupBraces(entity, []rune("\n```"+preCode.Language+"\n"), codeRunes)
|
||||||
case client.TypeTextEntityTypeTextUrl:
|
case client.TypeTextEntityTypeTextUrl:
|
||||||
textURL, _ := entity.Type.(*client.TextEntityTypeTextUrl)
|
textURL, _ := entity.Type.(*client.TextEntityTypeTextUrl)
|
||||||
return markupBraces(entity, urlRuneL, []rune("]("+textURL.Url+")"))
|
return markupBraces(entity, []rune("["), []rune("]("+textURL.Url+")"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format traverses an already sorted list of entities and wraps the text in Markdown
|
// EntityToXEP0393 generates the wrapping XEP-0393 tags
|
||||||
|
func EntityToXEP0393(entity *client.TextEntity) (*Insertion, *Insertion) {
|
||||||
|
switch entity.Type.TextEntityTypeType() {
|
||||||
|
case client.TypeTextEntityTypeBold:
|
||||||
|
return markupBraces(entity, boldRunesXEP0393, boldRunesXEP0393)
|
||||||
|
case client.TypeTextEntityTypeItalic:
|
||||||
|
return markupBraces(entity, italicRunes, italicRunes)
|
||||||
|
case client.TypeTextEntityTypeCode, client.TypeTextEntityTypePre:
|
||||||
|
return markupBraces(entity, codeRunes, codeRunes)
|
||||||
|
case client.TypeTextEntityTypePreCode:
|
||||||
|
preCode, _ := entity.Type.(*client.TextEntityTypePreCode)
|
||||||
|
// TODO: inline code support (non-standard too)
|
||||||
|
return markupBraces(entity, []rune("\n```"+preCode.Language+"\n"), codeRunes)
|
||||||
|
case client.TypeTextEntityTypeTextUrl:
|
||||||
|
textURL, _ := entity.Type.(*client.TextEntityTypeTextUrl)
|
||||||
|
// non-standard, Pidgin-specific
|
||||||
|
return markupBraces(entity, []rune{}, []rune(" <"+textURL.Url+">"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format traverses an already sorted list of entities and wraps the text in a markup
|
||||||
func Format(
|
func Format(
|
||||||
sourceText string,
|
sourceText string,
|
||||||
entities []*client.TextEntity,
|
entities []*client.TextEntity,
|
||||||
|
|
|
@ -237,7 +237,7 @@ func (c *Client) updateNewMessage(update *client.UpdateNewMessage) {
|
||||||
|
|
||||||
// message content updated
|
// message content updated
|
||||||
func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
|
func (c *Client) updateMessageContent(update *client.UpdateMessageContent) {
|
||||||
markupFunction := formatter.EntityToMarkdown
|
markupFunction := formatter.EntityToXEP0393
|
||||||
if update.NewContent.MessageContentType() == client.TypeMessageText {
|
if update.NewContent.MessageContentType() == client.TypeMessageText {
|
||||||
textContent := update.NewContent.(*client.MessageText)
|
textContent := update.NewContent.(*client.MessageText)
|
||||||
text := fmt.Sprintf("✎ %v | %s", update.MessageID, formatter.Format(
|
text := fmt.Sprintf("✎ %v | %s", update.MessageID, formatter.Format(
|
||||||
|
|
|
@ -292,7 +292,7 @@ func (c *Client) messageToText(message *client.Message) string {
|
||||||
return "<BIG EMOJI>"
|
return "<BIG EMOJI>"
|
||||||
}
|
}
|
||||||
|
|
||||||
markupFunction := formatter.EntityToMarkdown
|
markupFunction := formatter.EntityToXEP0393
|
||||||
switch message.Content.MessageContentType() {
|
switch message.Content.MessageContentType() {
|
||||||
case client.TypeMessageSticker:
|
case client.TypeMessageSticker:
|
||||||
sticker, _ := message.Content.(*client.MessageSticker)
|
sticker, _ := message.Content.(*client.MessageSticker)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp"
|
||||||
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tgConf config.TelegramConfig
|
var tgConf config.TelegramConfig
|
||||||
|
@ -22,7 +23,7 @@ var db *persistence.SessionsYamlDB
|
||||||
func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.StreamManager, *xmpp.Component, error) {
|
func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.StreamManager, *xmpp.Component, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
gateway.Jid, err = xmpp.NewJid(conf.Jid)
|
gateway.Jid, err = stanza.NewJid(conf.Jid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -30,8 +31,11 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
|
||||||
tgConf = tc
|
tgConf = tc
|
||||||
|
|
||||||
options := xmpp.ComponentOptions{
|
options := xmpp.ComponentOptions{
|
||||||
|
TransportConfiguration: xmpp.TransportConfiguration{
|
||||||
Address: conf.Host + ":" + conf.Port,
|
Address: conf.Host + ":" + conf.Port,
|
||||||
Domain: conf.Jid,
|
Domain: conf.Jid,
|
||||||
|
},
|
||||||
|
Domain: conf.Jid,
|
||||||
Secret: conf.Password,
|
Secret: conf.Password,
|
||||||
Name: "telegabber",
|
Name: "telegabber",
|
||||||
}
|
}
|
||||||
|
@ -41,7 +45,9 @@ func NewComponent(conf config.XMPPConfig, tc config.TelegramConfig) (*xmpp.Strea
|
||||||
router.HandleFunc("presence", HandlePresence)
|
router.HandleFunc("presence", HandlePresence)
|
||||||
router.HandleFunc("message", HandleMessage)
|
router.HandleFunc("message", HandleMessage)
|
||||||
|
|
||||||
component, err := xmpp.NewComponent(options, router)
|
component, err := xmpp.NewComponent(options, router, func(err error) {
|
||||||
|
log.Error(err)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ type IqVcardTemp struct {
|
||||||
N IqVcardN
|
N IqVcardN
|
||||||
Tel IqVcardTel
|
Tel IqVcardTel
|
||||||
Photo IqVcardPhoto
|
Photo IqVcardPhoto
|
||||||
|
ResultSet *stanza.ResultSet `xml:"set,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IqVcardFn is vCard/FN
|
// IqVcardFn is vCard/FN
|
||||||
|
@ -118,6 +119,11 @@ func (c IqVcardTemp) Namespace() string {
|
||||||
return c.XMLName.Space
|
return c.XMLName.Space
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Namespace is a namespace!
|
||||||
|
func (c IqVcardTemp) GetSet() *stanza.ResultSet {
|
||||||
|
return c.ResultSet
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// presence nick
|
// presence nick
|
||||||
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
|
stanza.TypeRegistry.MapExtension(stanza.PKTPresence, xml.Name{
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
var Queue = make(map[string]*stanza.Presence)
|
var Queue = make(map[string]*stanza.Presence)
|
||||||
|
|
||||||
// Jid stores the component's JID object
|
// Jid stores the component's JID object
|
||||||
var Jid *xmpp.Jid
|
var Jid *stanza.Jid
|
||||||
|
|
||||||
// SendMessage creates and sends a message stanza
|
// SendMessage creates and sends a message stanza
|
||||||
func SendMessage(to string, from string, body string, component *xmpp.Component) {
|
func SendMessage(to string, from string, body string, component *xmpp.Component) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ func logPacketType(p stanza.Packet) {
|
||||||
|
|
||||||
// HandleIq processes an incoming XMPP iq
|
// HandleIq processes an incoming XMPP iq
|
||||||
func HandleIq(s xmpp.Sender, p stanza.Packet) {
|
func HandleIq(s xmpp.Sender, p stanza.Packet) {
|
||||||
iq, ok := p.(stanza.IQ)
|
iq, ok := p.(*stanza.IQ)
|
||||||
if !ok {
|
if !ok {
|
||||||
logPacketType(p)
|
logPacketType(p)
|
||||||
return
|
return
|
||||||
|
@ -60,7 +60,7 @@ func HandleMessage(s xmpp.Sender, p stanza.Packet) {
|
||||||
}).Warn("Message")
|
}).Warn("Message")
|
||||||
log.Debugf("%#v", msg)
|
log.Debugf("%#v", msg)
|
||||||
|
|
||||||
fromJid, err := xmpp.NewJid(msg.From)
|
fromJid, err := stanza.NewJid(msg.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Invalid from JID!")
|
log.Error("Invalid from JID!")
|
||||||
return
|
return
|
||||||
|
@ -155,7 +155,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
log.Debugf("%#v", p)
|
log.Debugf("%#v", p)
|
||||||
|
|
||||||
// create session
|
// create session
|
||||||
fromJid, err := xmpp.NewJid(p.From)
|
fromJid, err := stanza.NewJid(p.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Invalid from JID!")
|
log.Error("Invalid from JID!")
|
||||||
return
|
return
|
||||||
|
@ -196,13 +196,13 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleGetVcardTempIq(s xmpp.Sender, iq stanza.IQ) {
|
func handleGetVcardTempIq(s xmpp.Sender, iq *stanza.IQ) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"from": iq.From,
|
"from": iq.From,
|
||||||
"to": iq.To,
|
"to": iq.To,
|
||||||
}).Warn("VCard request")
|
}).Warn("VCard request")
|
||||||
|
|
||||||
fromJid, err := xmpp.NewJid(iq.From)
|
fromJid, err := stanza.NewJid(iq.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Invalid from JID!")
|
log.Error("Invalid from JID!")
|
||||||
return
|
return
|
||||||
|
@ -274,5 +274,5 @@ func handleGetVcardTempIq(s xmpp.Sender, iq stanza.IQ) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = gateway.ResumableSend(component, answer)
|
_ = gateway.ResumableSend(component, &answer)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue