mirror of
https://github.com/mautrix/whatsapp.git
synced 2025-03-14 14:15:38 +00:00
pre-commit: add staticcheck
This commit is contained in:
parent
c78f2ba1dc
commit
902641f579
8 changed files with 45 additions and 28 deletions
7
.github/workflows/go.yml
vendored
7
.github/workflows/go.yml
vendored
|
@ -8,8 +8,8 @@ jobs:
|
|||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
go-version: ["1.21", "1.22"]
|
||||
name: Lint ${{ matrix.go-version == '1.22' && '(latest)' || '(old)' }}
|
||||
go-version: ["1.22", "1.23"]
|
||||
name: Lint ${{ matrix.go-version == '1.23' && '(latest)' || '(old)' }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
@ -23,9 +23,10 @@ jobs:
|
|||
- name: Install libolm
|
||||
run: sudo apt-get install libolm-dev libolm3
|
||||
|
||||
- name: Install goimports
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
go install golang.org/x/tools/cmd/goimports@latest
|
||||
go install honnef.co/go/tools/cmd/staticcheck@latest
|
||||
export PATH="$HOME/go/bin:$PATH"
|
||||
|
||||
- name: Install pre-commit
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.5.0
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
exclude_types: [markdown]
|
||||
|
@ -12,10 +12,26 @@ repos:
|
|||
rev: v1.0.0-rc.1
|
||||
hooks:
|
||||
- id: go-imports-repo
|
||||
args: ["-w"]
|
||||
args:
|
||||
- "-local"
|
||||
- "maunium.net/go/mautrix-whatsapp"
|
||||
- "-w"
|
||||
- id: go-vet-repo-mod
|
||||
# TODO switch to standard staticcheck after deleting old bridge
|
||||
#- id: go-staticcheck-repo-mod
|
||||
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: go-staticcheck-custom
|
||||
name: go-staticcheck-custom
|
||||
language: system
|
||||
types: [go]
|
||||
pass_filenames: false
|
||||
entry: sh -c 'staticcheck $(go list ./cmd/... ./pkg/...)'
|
||||
|
||||
- repo: https://github.com/beeper/pre-commit-go
|
||||
rev: v0.3.1
|
||||
hooks:
|
||||
- id: zerolog-ban-msgf
|
||||
# TODO enable after deleting old bridge
|
||||
#- id: zerolog-use-stringer
|
||||
|
|
|
@ -26,6 +26,7 @@ ALTER TABLE "user" RENAME TO user_old;
|
|||
//go:embed legacymigrate.sql
|
||||
var legacyMigrateCopyData string
|
||||
|
||||
//lint:ignore U1000 - TODO use this function
|
||||
func migrateLegacyConfig(helper up.Helper) {
|
||||
helper.Set(up.Str, "maunium.net/go/mautrix-whatsapp", "encryption", "pickle_key")
|
||||
bridgeconfig.CopyToOtherLocation(helper, up.Str, []string{"bridge", "displayname_template"}, []string{"network", "displayname_template"})
|
||||
|
|
|
@ -35,8 +35,9 @@ var whatsappCaps = &bridgev2.NetworkRoomCapabilities{
|
|||
},
|
||||
Files: map[event.MessageType]bridgev2.FileRestriction{
|
||||
event.MsgImage: {
|
||||
MaxSize: WAMaxFileSize,
|
||||
MimeTypes: []string{"image/png", "image/jpeg"},
|
||||
MaxSize: WAMaxFileSize,
|
||||
// webp isn't actually allowed, but will be converted to png
|
||||
MimeTypes: []string{"image/png", "image/jpeg", "image/webp"},
|
||||
},
|
||||
event.MsgAudio: {
|
||||
MaxSize: WAMaxFileSize,
|
||||
|
|
|
@ -15,7 +15,7 @@ type MediaRequestMethod string
|
|||
|
||||
const (
|
||||
MediaRequestMethodImmediate MediaRequestMethod = "immediate"
|
||||
MediaRequestMethodLocalTime = "local_time"
|
||||
MediaRequestMethodLocalTime MediaRequestMethod = "local_time"
|
||||
)
|
||||
|
||||
//go:embed example-config.yaml
|
||||
|
|
|
@ -49,7 +49,7 @@ func (evt *WAMessageEvent) GetTargetMessage() networkid.MessageID {
|
|||
key := reactionMsg.GetKey()
|
||||
senderID := key.GetParticipant()
|
||||
if senderID == "" {
|
||||
if key.GetFromMe() == true {
|
||||
if key.GetFromMe() {
|
||||
senderID = evt.Info.Sender.ToNonAD().String()
|
||||
} else {
|
||||
senderID = evt.wa.Client.Store.ID.ToNonAD().String() // could be false in groups
|
||||
|
@ -61,7 +61,7 @@ func (evt *WAMessageEvent) GetTargetMessage() networkid.MessageID {
|
|||
key := protocolMsg.GetKey()
|
||||
senderID := key.GetParticipant()
|
||||
if senderID == "" {
|
||||
if key.GetFromMe() == true {
|
||||
if key.GetFromMe() {
|
||||
senderID = evt.Info.Sender.ToNonAD().String()
|
||||
} else {
|
||||
senderID = evt.wa.Client.Store.ID.ToNonAD().String() // could be false in groups
|
||||
|
|
|
@ -41,6 +41,7 @@ func (wa *WhatsAppClient) messageIDToKey(id *waid.ParsedMessageID) *waCommon.Mes
|
|||
return key
|
||||
}
|
||||
|
||||
//lint:ignore U1000 - TODO use this function
|
||||
func (wa *WhatsAppClient) keyToMessageID(chat, sender types.JID, key *waCommon.MessageKey) networkid.MessageID {
|
||||
sender = sender.ToNonAD()
|
||||
var err error
|
||||
|
|
|
@ -314,6 +314,9 @@ func (mc *MessageConverter) reuploadFileToWhatsApp(ctx context.Context, client *
|
|||
fileName = content.FileName
|
||||
}
|
||||
data, err := mc.Bridge.Bot.DownloadMedia(ctx, content.URL, content.File)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("%w: %w", bridgev2.ErrMediaDownloadFailed, err)
|
||||
}
|
||||
|
||||
if mime == "" {
|
||||
mime = http.DetectContentType(data)
|
||||
|
@ -325,47 +328,41 @@ func (mc *MessageConverter) reuploadFileToWhatsApp(ctx context.Context, client *
|
|||
mediaType = whatsmeow.MediaImage
|
||||
mime = "image/webp"
|
||||
|
||||
var convertErr error
|
||||
data, convertErr = mc.convertToWebP(data)
|
||||
if convertErr != nil {
|
||||
return nil, "image/webp", fmt.Errorf("error converting image to webp: %s", convertErr.Error())
|
||||
data, err = mc.convertToWebP(data)
|
||||
if err != nil {
|
||||
return nil, "image/webp", fmt.Errorf("%w (to webp): %w", bridgev2.ErrMediaConvertFailed, err)
|
||||
}
|
||||
case event.MsgImage:
|
||||
if mime == "image/gif" {
|
||||
mediaType = whatsmeow.MediaVideo
|
||||
content.MsgType = event.MsgVideo
|
||||
if ffmpeg.Supported() {
|
||||
var convertErr error
|
||||
data, convertErr = ffmpeg.ConvertBytes(ctx, data, ".mp4", []string{"-f", "gif"}, []string{
|
||||
data, err = ffmpeg.ConvertBytes(ctx, data, ".mp4", []string{"-f", "gif"}, []string{
|
||||
"-pix_fmt", "yuv420p", "-c:v", "libx264", "-movflags", "+faststart",
|
||||
"-filter:v", "crop='floor(in_w/2)*2:floor(in_h/2)*2'",
|
||||
}, mime)
|
||||
|
||||
if convertErr != nil {
|
||||
return nil, "image/gif", fmt.Errorf("error converting gif to mp4: %s", convertErr.Error())
|
||||
if err != nil {
|
||||
return nil, "image/gif", fmt.Errorf("%w (gif to mp4): %w", bridgev2.ErrMediaConvertFailed, err)
|
||||
}
|
||||
mime = "video/mp4"
|
||||
}
|
||||
} else {
|
||||
mediaType = whatsmeow.MediaImage
|
||||
if mime == "image/webp" {
|
||||
var convertErr error
|
||||
data, convertErr = mc.convertToWebP(data)
|
||||
if convertErr != nil {
|
||||
return nil, "image/webp", fmt.Errorf("error converting webp to png: %s", convertErr.Error())
|
||||
data, err = mc.convertWebPtoPNG(data)
|
||||
if err != nil {
|
||||
return nil, "image/webp", fmt.Errorf("%w (webp to png): %s", bridgev2.ErrMediaConvertFailed, err)
|
||||
}
|
||||
mime = "image/png"
|
||||
}
|
||||
}
|
||||
case event.MsgVideo:
|
||||
if mime == "video/webm" {
|
||||
var convertErr error
|
||||
data, convertErr = ffmpeg.ConvertBytes(ctx, data, ".mp4", []string{"-f", "webm"}, []string{
|
||||
data, err = ffmpeg.ConvertBytes(ctx, data, ".mp4", []string{"-f", "webm"}, []string{
|
||||
"-pix_fmt", "yuv420p", "-c:v", "libx264",
|
||||
}, mime)
|
||||
|
||||
if convertErr != nil {
|
||||
return nil, "image/gif", fmt.Errorf("error converting webm to mp4: %s", convertErr.Error())
|
||||
if err != nil {
|
||||
return nil, "image/gif", fmt.Errorf("%w (webm to mp4): %w", bridgev2.ErrMediaConvertFailed, err)
|
||||
}
|
||||
mime = "video/mp4"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue