From 42092970a7d66648393393506a77c48d33b1174f Mon Sep 17 00:00:00 2001 From: Liam Stanley Date: Fri, 20 Jan 2017 06:48:42 -0500 Subject: [PATCH] remove Event.String(); rename Raw() to String() --- caller.go | 2 +- client.go | 2 +- event.go | 52 ++++------------------------------------------------ 3 files changed, 6 insertions(+), 50 deletions(-) diff --git a/caller.go b/caller.go index 2838a3c..fc05a78 100644 --- a/caller.go +++ b/caller.go @@ -14,7 +14,7 @@ import ( // RunCallbacks manually runs callbacks for a given event. func (c *Client) RunCallbacks(event *Event) { // Log the event. - c.log.Print("<-- " + StripRaw(event.Raw())) + c.log.Print("<-- " + StripRaw(event.String())) // Regular wildcard callbacks. c.Callbacks.exec(ALLEVENTS, c, event) diff --git a/client.go b/client.go index a6d5e4e..179a571 100644 --- a/client.go +++ b/client.go @@ -388,7 +388,7 @@ func (c *Client) Send(event *Event) error { func (c *Client) write(event *Event) error { // log the event if !event.Sensitive { - c.log.Print("--> ", StripRaw(event.Raw())) + c.log.Print("--> ", StripRaw(event.String())) } return c.state.writer.Encode(event) diff --git a/event.go b/event.go index 79f7b97..dda68f3 100644 --- a/event.go +++ b/event.go @@ -6,7 +6,6 @@ package girc import ( "bytes" - "fmt" "strings" "time" ) @@ -209,56 +208,12 @@ func (e *Event) Bytes() []byte { return out } -// Raw returns a string representation of this event. Strips all newlines +// String returns a string representation of this event. Strips all newlines // and carriage returns. -func (e *Event) Raw() string { +func (e *Event) String() string { return string(e.Bytes()) } -// String returns a prettified string representation of this event. Strips -// all newlines and carriage returns. -// -// Per RFC2812 section 2.3, messages should not exceed 512 characters in -// length. This method forces that limit by discarding any characters -// exceeding the length limit. -func (e *Event) String() (out string) { - // Event prefix. - if e.Source != nil { - if e.Source.Name != "" { - out += fmt.Sprintf("[%s] ", e.Source.Name) - } else { - out += fmt.Sprintf("[%s] ", e.Source) - } - } - - // Command is required. - out += e.Command - - // Space separated list of arguments. - if len(e.Params) > 0 { - out += " " + strings.Join(e.Params, string(eventSpace)) - } - - if len(e.Trailing) > 0 || e.EmptyTrailing { - out += " :" + e.Trailing - } - - // We need the limit the buffer length. - if len(out) > (maxLength) { - out = out[0 : maxLength-1] - } - - // Strip newlines and carriage returns. - for i := 0; i < len(out); i++ { - if out[i] == 0x0A || out[i] == 0x0D { - out = out[:i] + out[i+1:] - i-- // Decrease the index so we can pick up where we left off. - } - } - - return out -} - // IsAction checks to see if the event is a PRIVMSG, and is an ACTION (/me). func (e *Event) IsAction() bool { if len(e.Trailing) <= 0 || e.Command != PRIVMSG { @@ -300,7 +255,8 @@ func (e *Event) IsFromUser() bool { return true } -// StripAction strips the action encoding from a PRIVMSG ACTION (/me). +// StripAction returns the stripped version of the action encoding from a +// PRIVMSG ACTION (/me). func (e *Event) StripAction() string { if !e.IsAction() || len(e.Trailing) < 9 { return e.Trailing