mirror of
https://github.com/jackmerrill/hampbot.git
synced 2024-12-04 13:02:59 -08:00
use diffs for msg edit
This commit is contained in:
parent
658db4d051
commit
b7c005581b
2
fly.toml
2
fly.toml
|
@ -12,7 +12,7 @@ primary_region = "bos"
|
|||
build-target = "runner"
|
||||
|
||||
[http_service]
|
||||
auto_stop_machines = "stop"
|
||||
auto_stop_machines = false
|
||||
auto_start_machines = true
|
||||
min_machines_running = 1
|
||||
processes = ["app"]
|
||||
|
|
1
go.mod
1
go.mod
|
@ -17,6 +17,7 @@ require (
|
|||
github.com/kennygrant/sanitize v1.2.4 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
|
||||
github.com/sergi/go-diff v1.3.1 // indirect
|
||||
github.com/temoto/robotstxt v1.1.1 // indirect
|
||||
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
|
||||
google.golang.org/appengine v1.6.6 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -172,6 +172,8 @@ github.com/sarulabs/di/v2 v2.4.2 h1:A/PDVU41gHYeUbZZKco8dOwPAB2rrFfiwWLJrZsi+h8=
|
|||
github.com/sarulabs/di/v2 v2.4.2/go.mod h1:trZu4KPwNLE623mBIIsljn1LLkNE6ee/Pk24b7yzSf8=
|
||||
github.com/sashabaranov/go-openai v1.14.2 h1:5DPTtR9JBjKPJS008/A409I5ntFhUPPGCmaAihcPRyo=
|
||||
github.com/sashabaranov/go-openai v1.14.2/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
|
||||
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
|
@ -340,6 +342,7 @@ google.golang.org/protobuf v1.24.0 h1:UhZDfRO8JRQru4/+LlLE0BRKGF8L+PICnvYZmx/fEG
|
|||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/ryankurte/go-mapbox.v0 v0.4.2 h1:i3wBfUnTxI7NNg4BiatUAzSAzfA9Cxpc0WWhOHBCMQg=
|
||||
gopkg.in/ryankurte/go-mapbox.v0 v0.4.2/go.mod h1:HxwTAU0Ia8hfMMhlohUGyCbjSJwSzQYaZ4dmJSCEuiE=
|
||||
|
@ -348,6 +351,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/jackmerrill/hampbot/internal/utils/config"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
||||
type MessageEditListener struct{}
|
||||
|
@ -27,21 +28,28 @@ func (l *MessageEditListener) Exec(s *discordgo.Session, e *discordgo.MessageUpd
|
|||
},
|
||||
}
|
||||
|
||||
diffText := ""
|
||||
|
||||
if o, ok := config.MessageLog[e.ID]; ok {
|
||||
old = o
|
||||
|
||||
fields = append(fields, &discordgo.MessageEmbedField{
|
||||
Name: "Old",
|
||||
Value: old.Content,
|
||||
Inline: false,
|
||||
})
|
||||
dmp := diffmatchpatch.New()
|
||||
|
||||
fileAdmp, fileBdmp, dmpStrings := dmp.DiffLinesToChars(old.Content, e.Content)
|
||||
diffs := dmp.DiffMain(fileAdmp, fileBdmp, false)
|
||||
diffs = dmp.DiffCharsToLines(diffs, dmpStrings)
|
||||
diffs = dmp.DiffCleanupSemantic(diffs)
|
||||
|
||||
for _, d := range diffs {
|
||||
if d.Type == diffmatchpatch.DiffInsert {
|
||||
diffText += fmt.Sprintf("+ %s\n", d.Text)
|
||||
}
|
||||
if d.Type == diffmatchpatch.DiffDelete {
|
||||
diffText += fmt.Sprintf("- %s\n", d.Text)
|
||||
}
|
||||
}
|
||||
|
||||
fields = append(fields, &discordgo.MessageEmbedField{
|
||||
Name: "New",
|
||||
Value: e.Content,
|
||||
Inline: false,
|
||||
})
|
||||
}
|
||||
|
||||
var image *discordgo.MessageEmbedImage
|
||||
|
||||
|
@ -56,8 +64,8 @@ func (l *MessageEditListener) Exec(s *discordgo.Session, e *discordgo.MessageUpd
|
|||
Title: "Message edited",
|
||||
Fields: fields,
|
||||
Description: fmt.Sprintf(
|
||||
"[Jump to message](https://discordapp.com/channels/%s/%s/%s)",
|
||||
e.GuildID, e.ChannelID, e.ID,
|
||||
"[Jump to message](https://discordapp.com/channels/%s/%s/%s)\n\n```diff\n%s```",
|
||||
e.GuildID, e.ChannelID, e.ID, diffText,
|
||||
),
|
||||
Color: 0xffff00,
|
||||
Image: image,
|
||||
|
|
Loading…
Reference in New Issue
Block a user