Add OnMessageEdit to JS API
MODIFY
scripting/engine.go
scripting/engine.go
@@ -20,6 +20,9 @@ type Engine interface {
// OnMessageReceive gets called every time a message is received, no matter
// in which channel or guild.
OnMessageReceive(*discordgo.Message)
+ // OnMessageEdit gets called every time a message is edited, no matter in
+ // which channel or guild.
+ OnMessageEdit(*discordgo.Message)
// OnMessageDelete gets called every time a message gets deleted, no matter
// in which channel or guild.
OnMessageDelete(*discordgo.Message)

MODIFY
scripting/js/javascript.go
scripting/js/javascript.go
@@ -114,7 +114,7 @@ func (engine *JavaScriptEngine) OnMessageSend(oldText string) (newText string) {
return
}
-// OnMessageRead implements Engine
+// OnMessageReceive implements Engine
func (engine *JavaScriptEngine) OnMessageReceive(message *discordgo.Message) {
for _, vm := range engine.vms {
onMessageReceiveJS, resolveError := vm.Get("onMessageReceive")
@@ -138,6 +138,29 @@ func (engine *JavaScriptEngine) OnMessageReceive(message *discordgo.Message) {
}
}
+// OnMessageEdit implements Engine
+func (engine *JavaScriptEngine) OnMessageEdit(message *discordgo.Message) {
+ for _, vm := range engine.vms {
+ onMessageEditJS, resolveError := vm.Get("onMessageEdit")
+ if onMessageEditJS.IsUndefined() {
+ continue
+ }
+ if resolveError != nil {
+ log.Printf("Error resolving function onMessageEdit: %s\n", resolveError)
+ continue
+ }
+
+ messageToJS, toValueError := vm.ToValue(*message)
+ if toValueError != nil {
+ log.Printf("Error converting message to Otto value: %s\n", toValueError)
+ } else {
+ _, callError := onMessageEditJS.Call(otto.NullValue(), messageToJS)
+ if callError != nil {
+ log.Printf("Error calling onMessageEdit: %s\n", callError)
+ }
+ }
+ }
+}
// OnMessageDelete implements Engine
func (engine *JavaScriptEngine) OnMessageDelete(message *discordgo.Message) {
for _, vm := range engine.vms {

MODIFY
ui/window.go
ui/window.go
@@ -1658,6 +1658,7 @@ func (window *Window) startMessageHandlerRoutines(input, edit, delete chan *disc
go func() {
for messageEdited := range edit {
tempMessageEdited := messageEdited
+ go window.jsEngine.OnMessageEdit(tempMessageEdited)
window.chatView.Lock()
if window.selectedChannel != nil && window.selectedChannel.ID == tempMessageEdited.ChannelID {
for _, message := range window.chatView.data {

Add OnMessageEdit to JS API