diff --git a/caller.go b/caller.go index 808d38f..607d66b 100644 --- a/caller.go +++ b/caller.go @@ -23,13 +23,13 @@ func (c *Client) RunCallbacks(event *Event) { c.debug.Print("< " + StripRaw(event.String())) // Regular wildcard callbacks. - c.Callbacks.exec(ALLEVENTS, c, event) + c.Callbacks.exec(ALLEVENTS, c, event.Copy()) // Then regular callbacks. - c.Callbacks.exec(event.Command, c, event) + c.Callbacks.exec(event.Command, c, event.Copy()) // Check if it's a CTCP. - if ctcp := decodeCTCP(event); ctcp != nil { + if ctcp := decodeCTCP(event.Copy()); ctcp != nil { // Execute it. c.CTCP.call(ctcp, c) } diff --git a/event.go b/event.go index 1bb1b3c..f61e8d0 100644 --- a/event.go +++ b/event.go @@ -125,6 +125,25 @@ func ParseEvent(raw string) (e *Event) { return e } +func (e *Event) Copy() *Event { + newEvent := &Event{} + + *newEvent = *e + + // Copy Source field, as it's a pointer and needs to be dereferenced. + *newEvent.Source = *e.Source + + // Copy tags as necessary. + if e.Tags != nil { + newEvent.Tags = Tags{} + for k, v := range e.Tags { + newEvent.Tags[k] = v + } + } + + return newEvent +} + // Len calculates the length of the string representation of event. func (e *Event) Len() (length int) { if e.Tags != nil {