utilize ErrNotConnected within helper functions
This commit is contained in:
parent
6adc5ee783
commit
54c3215dd4
38
main.go
38
main.go
@ -107,7 +107,7 @@ type ErrCallbackTimedout struct {
|
||||
}
|
||||
|
||||
func (e *ErrCallbackTimedout) Error() string {
|
||||
return "callback [" + e.ID + "] timed out while waiting for response from the server"
|
||||
return "callback [" + e.ID + "] timed out while waiting for response from the server: " + e.Timeout.String()
|
||||
}
|
||||
|
||||
// ErrNotConnected is returned if a method is used when the client isn't
|
||||
@ -419,6 +419,10 @@ func (c *Client) GetNick() string {
|
||||
|
||||
// SetNick changes the client nickname.
|
||||
func (c *Client) SetNick(name string) error {
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
if !IsValidNick(name) {
|
||||
return &ErrInvalidTarget{Target: name}
|
||||
}
|
||||
@ -453,6 +457,10 @@ func (c *Client) Who(target string) error {
|
||||
return &ErrInvalidTarget{Target: target}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
return c.Send(&Event{Command: WHO, Params: []string{target, "%tcuhn,1"}})
|
||||
}
|
||||
|
||||
@ -462,6 +470,10 @@ func (c *Client) Join(channel, password string) error {
|
||||
return &ErrInvalidTarget{Target: channel}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
if password != "" {
|
||||
return c.Send(&Event{Command: JOIN, Params: []string{channel, password}})
|
||||
}
|
||||
@ -475,6 +487,10 @@ func (c *Client) Part(channel, message string) error {
|
||||
return &ErrInvalidTarget{Target: channel}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
if message != "" {
|
||||
return c.Send(&Event{Command: JOIN, Params: []string{channel}, Trailing: message})
|
||||
}
|
||||
@ -489,6 +505,10 @@ func (c *Client) Message(target, message string) error {
|
||||
return &ErrInvalidTarget{Target: target}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
return c.Send(&Event{Command: PRIVMSG, Params: []string{target}, Trailing: message})
|
||||
}
|
||||
|
||||
@ -505,6 +525,10 @@ func (c *Client) Action(target, message string) error {
|
||||
return &ErrInvalidTarget{Target: target}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
return c.Send(&Event{
|
||||
Command: PRIVMSG,
|
||||
Params: []string{target},
|
||||
@ -524,6 +548,10 @@ func (c *Client) Notice(target, message string) error {
|
||||
return &ErrInvalidTarget{Target: target}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
return c.Send(&Event{Command: NOTICE, Params: []string{target}, Trailing: message})
|
||||
}
|
||||
|
||||
@ -540,6 +568,10 @@ func (c *Client) SendRaw(raw string) error {
|
||||
return errors.New("invalid event: " + raw)
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return ErrNotConnected
|
||||
}
|
||||
|
||||
return c.Send(e)
|
||||
}
|
||||
|
||||
@ -556,6 +588,10 @@ func (c *Client) Whowas(nick string) ([]*User, error) {
|
||||
return nil, &ErrInvalidTarget{Target: nick}
|
||||
}
|
||||
|
||||
if !c.state.connected {
|
||||
return nil, ErrNotConnected
|
||||
}
|
||||
|
||||
var mu sync.Mutex
|
||||
var events []*Event
|
||||
whoDone := make(chan struct{})
|
||||
|
Loading…
Reference in New Issue
Block a user