Rename onMessage Event to onMessageSend
MODIFY
internal/scripting/engine.go
internal/scripting/engine.go
@@ -3,6 +3,8 @@ package scripting
// Engine describes a type that is capable of handling events from the main
// application and allows mutation of data.
type Engine interface {
- LoadScripts(string) error // loads scripts from a directory into the VM
- OnMessage(string) string // OnMessage handles new messages
+ // LoadScripts loads scripts from a directory into the VM
+ LoadScripts(string) error
+ // OnMessageSend handles the client sending new messages
+ OnMessageSend(string) string
}

MODIFY
internal/scripting/javascript.go
internal/scripting/javascript.go
@@ -52,8 +52,8 @@ func (engine *JavaScriptEngine) LoadScripts(dirname string) (err error) {
return err
}
-// OnMessage implements Engine
-func (engine *JavaScriptEngine) OnMessage(oldText string) (newText string) {
+// OnMessageSend implements Engine
+func (engine *JavaScriptEngine) OnMessageSend(oldText string) (newText string) {
jsValue, jsError := engine.vm.Run(fmt.Sprintf(`onMessage("%s")`, oldText))
if jsError != nil {
//TODO Return error?

MODIFY
internal/ui/window.go
internal/ui/window.go
@@ -426,7 +426,7 @@ func NewWindow(discord *discordgo.Session) (*Window, error) {
window.exitMessageEditMode()
} else {
go func() {
- _, sendError := discord.ChannelMessageSend(window.selectedChannel.ID, window.scripting.OnMessage(messageToSend))
+ _, sendError := discord.ChannelMessageSend(window.selectedChannel.ID, window.scripting.OnMessageSend(messageToSend))
if sendError != nil {
window.app.QueueUpdateDraw(func() {
window.ShowErrorDialog("Error sending message: " + sendError.Error())

Rename onMessage Event to onMessageSend