lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
137 stars 13 forks source link

client.LookupUser should never fail on own user #27

Closed nmeum closed 5 years ago

nmeum commented 5 years ago

client.LookupUser searches the data structure filled by state.createUser. Unfortunately, createUser is only called on JOIN and NAMES. Therefore LookupUser returns nil when passing ones own nick name as argument if one didn't join any channels yet.

This seemed unexpected to me. This commit therefore calls createUser for ones own nick on connect.

codecov-io commented 5 years ago

Codecov Report

Merging #27 into master will decrease coverage by 0.15%. The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
- Coverage   56.24%   56.09%   -0.16%     
==========================================
  Files          13       13              
  Lines        2329     2330       +1     
==========================================
- Hits         1310     1307       -3     
- Misses        912      915       +3     
- Partials      107      108       +1
Impacted Files Coverage Δ
builtin.go 61.73% <100%> (-0.59%) :arrow_down:
conn.go 58.84% <0%> (-0.83%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3aee8c2...ed764a0. Read the comment docs.

lrstanley commented 5 years ago

After a bit of thought -- I don't think this is the intended behavior I want to promote. For information on the active connection, you should be using methods attached to Client, not directly from the user map in state. The only time I want users in state to include the actual active connection, is in reference to channels.

The idea behind LookupUser/LookupChannel/[...] is that all of those users are only known due to the channels the client is currently in, not just "all of the known users" -- as, users are removed from state when the client is no longer in the channel, when they part the channel, etc.