diff --git a/io.go b/io.go index 39b11ef..ac2cf71 100644 --- a/io.go +++ b/io.go @@ -21,6 +21,32 @@ type Client struct { conn net.Conn } +// ID returns the Client Application ID nil-safely +func (d *Client) ID() string { + if d == nil { + return "" + } + return d.id +} + +// User returns the Client User nil-safely +func (d *Client) User() (User, bool) { + if d == nil || d.user == nil { + return User{}, false + } + return *d.user, true + +} + +// Config returns the Client Config nil-safely +func (d *Client) Config() (Config, bool) { + if d == nil || d.config == nil { + return Config{}, false + } + return *d.config, true + +} + // Raw wraps around the Raw method to provide generic json parsing func Raw[T any](d *Client, opcode uint32, payload any) (uint32, T, error) { var p T @@ -82,8 +108,7 @@ func (d *Client) raw(opcode uint32, payload any) (uint32, []byte, error) { // Close the client, this is required before exit func (d *Client) Close() error { - if !d.dialed { - // silently succeed because client activation is implicit + if d == nil || !d.dialed { return nil }