Look for random agents around me and try to befriend them
541291
def try_friends(self, others):
        ''' '''
        befriended = False
        k = int(10*self['openness'])
        shuffle(others)
        for friend in islice(others, k):  # random.choice >= 3.7
            if friend == self:
                continue
            if friend.befriend(self):
                self.befriend(friend, force=True)
                self.debug('Hooray! new friend: {}'.format(friend.id))
                befriended = True
            else:
                self.debug('{} does not want to be friends'.format(friend.id))
        return befriended
554694
def invited_by?(user)
      user.friend_ids.include?(self.id) or user.pending_friend_ids.include?(self.id)
    end
1042051
def friendship_create(id, follow=false)
      body = {}
      body.merge!(:follow => follow) if follow
      perform_post("/friendships/create/#{id}.json", :body => body)
    end
409092
def invited?(user)
      self.friend_ids.include?(user.id) or self.pending_friend_ids.include?(user.id)
    end
996
function onRequestGetAgents(session, channel, message) {
  var agents = session.getAgents()
  var infos  = agents.map(function(agent){
    return agent.info
  })

  channel.sendMessage({
    type:  "response",
    name:  message.name,
    from:  message.to,
    id:    message.id,
    body:  infos
  })

}
243658
def connect(self, agent='Python'):
        
        headers = {'User-Agent': agent}
        request = urlopen(Request(self.url, headers=headers))
        try:
            yield request
        finally:
            request.close()
800106
async def join(self, ctx):
        """"""
        perms = discord.Permissions.none()
        perms.read_messages = True
        perms.send_messages = True
        perms.manage_messages = True
        perms.embed_links = True
        perms.read_message_history = True
        perms.attach_files = True
        perms.add_reactions = True
        await self.bot.send_message(ctx.message.author, discord.utils.oauth_url(self.bot.client_id, perms))
842201
function Agent(channel, info) {
  this.channel = channel
  this.info = {
    id:     channel.nextAgentID(),
    name:   info.name,
    title:  info.title
  }
  DEBUG("new Agent(" + utils.JS(this.info) + ")")
}
67939
function FoundFriend (params) {
  var self = this
  if (!(self instanceof FoundFriend)) return new FoundFriend(params)

  self.displayName = params['display']
  self.username = params['name']
  self.isPrivate = !!params['type']
}
329451
function createAgent() {
    return new Socks.Agent({
            proxy: {
                ipaddress: process.argv[3],
                port: parseInt(process.argv[4]),
                type: parseInt(process.argv[2])
            }}
    );
}
1256577
def setup_network_agents(self):
        """"""
        for i in self.env.G.nodes():
            self.env.G.node[i]['agent'] = self.agent_type(environment=self.env, agent_id=i,
                                                          state=deepcopy(self.initial_states[i]))
1041138
function(callback) {
  tox.on('friendRequest', function(evt) {
    console.log('Accepting friend request from ' + evt.publicKeyHex());
    // Automatically accept the request
    tox.addFriendNoRequestAsync(evt.publicKey()).then(function() {
      console.log('Successfully accepted the friend request!');
    }).catch(function(err) {
      console.error('Couldn\'t accept the friend request:', err);
    });
  });

  tox.on('friendMessage', function(evt) {
    console.log('Message from friend ' + evt.friend() + ': ' + evt.message());
    // Echo message back to friend
    tox.sendMessageAsync(evt.friend(), evt.message()).then(function(receipt) {
      console.log('Echoed message back to friend, received receipt ' + receipt);
    }).catch(function(err) {
      console.error('Couldn\'t echo message back to friend:', err);
    });
  });

  // Setup friendMessage callback to listen for groupchat invite requests
  tox.on('friendMessage', function(evt) {
    if(evt.message() === 'invite text') {
      tox.inviteAsync(evt.friend(), groupchats['text']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the text groupchat');
      });
    } else if(evt.message() === 'invite av') {
      tox.inviteAsync(evt.friend(), groupchats['av']).then(function() {
        console.log('Invited ' + evt.friend() + ' to the audio/video groupchat');
      });
    }
  });

  callback();
}
950040
def get_friends(self, **params):
        """"""
        url = self.config['friends']
        return self.request_json(url, params=params)[0]
1302593
private void gossip() {
    List<Member> members = membershipService.getMembers()
        .stream()
        .filter(node -> !localMemberId.equals(node.id()))
        .filter(node -> node.isReachable())
        .collect(Collectors.toList());

    if (!members.isEmpty()) {
      Collections.shuffle(members);
      Member member = members.get(0);
      updateNode(member);
    }
  }
984070
private void gossip(Collection<ImmutableMember> updates) {
    // Get a list of available peers. If peers are available, randomize the peer list and select a subset of
    // peers with which to gossip updates.
    List<SwimMember> members = Lists.newArrayList(randomMembers);
    if (!members.isEmpty()) {
      Collections.shuffle(members);
      for (int i = 0; i < Math.min(members.size(), config.getGossipFanout()); i++) {
        gossip(members.get(i), updates);
      }
    }
  }
1113973
def start_agent(agent, recp, desc, allocation_id=None, *args, **kwargs):
    '''
    
    '''
    f = fiber.Fiber()
    f.add_callback(agent.initiate_protocol, IRecipient(recp), desc,
                   allocation_id, *args, **kwargs)
    f.add_callback(StartAgentRequester.notify_finish)
    f.succeed(StartAgentRequester)
    return f
835060
def add_node(self, node):
        """"""
        nodes = self.nodes()

        # Start with a core of m0 fully-connected agents...
        if len(nodes) <= self.m0:
            other_nodes = [n for n in nodes if n.id != node.id]
            for n in other_nodes:
                node.connect(direction="both", whom=n)

        # ...then add newcomers one by one with preferential attachment.
        else:
            for idx_newvector in xrange(self.m):

                these_nodes = [
                    n for n in nodes if (
                        n.id != node.id and
                        not n.is_connected(direction="either", whom=node))]

                outdegrees = [
                    len(n.vectors(direction="outgoing")) for n in these_nodes]

                # Select a member using preferential attachment
                ps = [(d / (1.0 * sum(outdegrees))) for d in outdegrees]
                rnd = random.random() * sum(ps)
                cur = 0.0
                for i, p in enumerate(ps):
                    cur += p
                    if rnd < cur:
                        vector_to = these_nodes[i]

                # Create vector from newcomer to selected member and back
                node.connect(direction="both", whom=vector_to)