look into supporting copy, without reflection

This commit is contained in:
Liam Stanley 2017-02-08 17:42:46 -05:00
parent caac8e8e8d
commit 7ba8001f27
2 changed files with 22 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {