mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-14 08:06:23 -07:00
Add message-pre-format event trigger
This commit is contained in:
parent
381dd42a28
commit
6d22c86df1
3 changed files with 41 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/gochan-org/gochan/pkg/building"
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/gochan-org/gochan/pkg/events"
|
||||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
"github.com/gochan-org/gochan/pkg/gctemplates"
|
||||
"github.com/gochan-org/gochan/pkg/gcutil"
|
||||
|
@ -193,6 +194,26 @@ func editPost(checkedPosts []int, editBtn string, doEdit string, writer http.Res
|
|||
}
|
||||
}
|
||||
} else {
|
||||
var recovered bool
|
||||
_, err, recovered = events.TriggerEvent("message-pre-format", post)
|
||||
if recovered {
|
||||
errEv.Caller().
|
||||
Str("triggeredEvent", "message-pre-format").
|
||||
Msg("Recovered from a panic in event handler")
|
||||
server.ServeError(writer, "Recovered from a panic in an event handler (message-pre-format)", wantsJSON, map[string]interface{}{
|
||||
"postid": post.ID,
|
||||
})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("triggeredEvent", "message-pre-format").
|
||||
Send()
|
||||
server.ServeError(writer, err.Error(), wantsJSON, map[string]interface{}{
|
||||
"postid": post.ID,
|
||||
})
|
||||
return
|
||||
}
|
||||
if err = post.UpdateContents(
|
||||
request.FormValue("editemail"),
|
||||
request.FormValue("editsubject"),
|
||||
|
|
|
@ -10,6 +10,9 @@ This is a list of events that gochan may trigger at some point, that can be used
|
|||
- **incoming-upload**
|
||||
- Triggered by the `gcsql` package when an upload is attached to a post. It is triggered before the upload is entered in the database
|
||||
|
||||
- **message-pre-format**
|
||||
- Triggered when an incoming post or post edit is about to be formatted
|
||||
|
||||
- **shutdown**
|
||||
- Triggered when gochan is about to shut down, in `main()` as a deferred call
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/gochan-org/gochan/pkg/building"
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/gochan-org/gochan/pkg/events"
|
||||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
"github.com/gochan-org/gochan/pkg/gcutil"
|
||||
"github.com/gochan-org/gochan/pkg/server"
|
||||
|
@ -160,6 +161,22 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
_, err, recovered := events.TriggerEvent("message-pre-format", post)
|
||||
if recovered {
|
||||
errEv.Caller().
|
||||
Str("triggeredEvent", "message-pre-format").
|
||||
Msg("Recovered from a panic in event handler")
|
||||
server.ServeError(writer, "Recovered from a panic in an event handler (message-pre-format)", wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("triggeredEvent", "message-pre-format").
|
||||
Send()
|
||||
server.ServeError(writer, err.Error(), wantsJSON, nil)
|
||||
return
|
||||
}
|
||||
|
||||
post.Message = FormatMessage(post.MessageRaw, postBoard.Dir)
|
||||
password := request.FormValue("postpassword")
|
||||
if password == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue