look into supporting copy, without reflection
This commit is contained in:
parent
caac8e8e8d
commit
7ba8001f27
@ -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)
|
||||
}
|
||||
|
19
event.go
19
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user