2024-08-13 14:11:10 +03:00
|
|
|
// mautrix-meta - A Matrix-Facebook Messenger and Instagram DM puppeting bridge.
|
|
|
|
|
// Copyright (C) 2024 Tulir Asokan
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
package msgconv
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"maunium.net/go/mautrix/bridgev2"
|
|
|
|
|
"maunium.net/go/mautrix/format"
|
2024-10-07 14:21:56 +03:00
|
|
|
|
2024-10-15 17:59:57 +03:00
|
|
|
"go.mau.fi/mautrix-whatsapp/pkg/connector/wadb"
|
2024-08-13 14:11:10 +03:00
|
|
|
)
|
|
|
|
|
|
2024-09-25 12:45:05 +03:00
|
|
|
type AnimatedStickerConfig struct {
|
|
|
|
|
Target string `yaml:"target"`
|
|
|
|
|
Args struct {
|
|
|
|
|
Width int `yaml:"width"`
|
|
|
|
|
Height int `yaml:"height"`
|
|
|
|
|
FPS int `yaml:"fps"`
|
|
|
|
|
} `yaml:"args"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 14:11:10 +03:00
|
|
|
type MessageConverter struct {
|
2024-09-25 12:45:05 +03:00
|
|
|
Bridge *bridgev2.Bridge
|
2024-10-07 14:21:56 +03:00
|
|
|
DB *wadb.Database
|
2024-09-25 12:45:05 +03:00
|
|
|
MaxFileSize int64
|
|
|
|
|
HTMLParser *format.HTMLParser
|
|
|
|
|
AnimatedStickerConfig AnimatedStickerConfig
|
2024-09-25 16:01:35 +03:00
|
|
|
FetchURLPreviews bool
|
2024-10-07 14:21:56 +03:00
|
|
|
ExtEvPolls bool
|
2024-10-07 17:13:20 +03:00
|
|
|
DisableViewOnce bool
|
2024-11-06 13:14:12 +01:00
|
|
|
DirectMedia bool
|
2024-10-01 17:23:43 +03:00
|
|
|
OldMediaSuffix string
|
2024-08-13 14:11:10 +03:00
|
|
|
}
|
|
|
|
|
|
2024-09-25 16:01:35 +03:00
|
|
|
func New(br *bridgev2.Bridge) *MessageConverter {
|
2024-08-13 14:11:10 +03:00
|
|
|
mc := &MessageConverter{
|
2024-09-25 16:01:35 +03:00
|
|
|
Bridge: br,
|
|
|
|
|
MaxFileSize: 50 * 1024 * 1024,
|
2024-08-13 14:11:10 +03:00
|
|
|
}
|
|
|
|
|
mc.HTMLParser = &format.HTMLParser{
|
|
|
|
|
PillConverter: mc.convertPill,
|
2024-09-25 16:25:52 +03:00
|
|
|
Newline: "\n",
|
|
|
|
|
TabsToSpaces: 4,
|
2024-08-13 14:11:10 +03:00
|
|
|
BoldConverter: func(text string, ctx format.Context) string {
|
|
|
|
|
return "*" + text + "*"
|
|
|
|
|
},
|
|
|
|
|
ItalicConverter: func(text string, ctx format.Context) string {
|
|
|
|
|
return "_" + text + "_"
|
|
|
|
|
},
|
|
|
|
|
StrikethroughConverter: func(text string, ctx format.Context) string {
|
|
|
|
|
return "~" + text + "~"
|
|
|
|
|
},
|
|
|
|
|
MonospaceConverter: func(text string, ctx format.Context) string {
|
|
|
|
|
return "`" + text + "`"
|
|
|
|
|
},
|
|
|
|
|
MonospaceBlockConverter: func(code, language string, ctx format.Context) string {
|
|
|
|
|
return "```\n" + code + "\n```"
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
return mc
|
|
|
|
|
}
|