Method: WeChat::Bot::ContactList#find

Defined in:
lib/wechat/bot/contact_list.rb

#find(**args) ⇒ Contact

查找用户

Parameters:

  • args (Hash)

    接受两个参数:

    • :nickname 昵称

    • :username 用户ID

Returns:



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wechat/bot/contact_list.rb', line 61

def find(**args)
  @mutex.synchronize do
    return @cache[args[:username]] if args[:username]

    if args[:nickname]
      @cache.each do |_, contact|
        return contact if contact.nickname == args[:nickname]
      end
    end
  end
end