1
0
Fork 0
mirror of https://github.com/mautrix/whatsapp.git synced 2026-05-15 10:16:52 -04:00
mautrix-whatsapp/pkg/msgconv/msgconv.go

74 lines
2.2 KiB
Go
Raw Permalink Normal View History

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"
"go.mau.fi/mautrix-whatsapp/pkg/connector/wadb"
2024-08-13 14:11:10 +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 {
Bridge *bridgev2.Bridge
DB *wadb.Database
MaxFileSize int64
HTMLParser *format.HTMLParser
AnimatedStickerConfig AnimatedStickerConfig
2024-09-25 16:01:35 +03:00
FetchURLPreviews bool
ExtEvPolls bool
DisableViewOnce bool
2024-11-06 13:14:12 +01:00
DirectMedia bool
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
}