List channels & users in slack.
424155
def list_slack():
    """"""
    try:
        token = os.environ['SLACK_TOKEN']
        slack = Slacker(token)

        # Get channel list
        response = slack.channels.list()
        channels = response.body['channels']
        for channel in channels:
            print(channel['id'], channel['name'])
            # if not channel['is_archived']:
            # slack.channels.join(channel['name'])
        print()

        # Get users list
        response = slack.users.list()
        users = response.body['members']
        for user in users:
            if not user['deleted']:
                print(user['id'], user['name'], user['is_admin'], user[
                    'is_owner'])
        print()
    except KeyError as ex:
        print('Environment variable %s not set.' % str(ex))
1008840
def _find_user_channel(self, username):
		
		user_id = self.slacker.users.get_user_id(username)
		im = user_id and self.slacker.im.open(user_id).body['channel']['id']
		return im and self.slack.server.channels.find(im)
217518
def list(ctx):
    """"""
    wva = get_wva(ctx)
    for subscription in wva.get_subscriptions():
        print(subscription.short_name)
486928
def names(self, channel):
        
        with self.lock:
            self.is_in_channel(channel)

            self.send('NAMES %s' % channel)
            names = []

            while self.readable():
                msg = self._recv(expected_replies=('353', '366'))

                if msg[0] == '353':
                    new_names = msg[2].split()[2:]
                    new_names[0] = new_names[0].replace(':', '', 1)
                    names.extend(new_names)
                elif msg[0] == '366':
                    channel = msg[2].split()[0]
                    break

            for name in names:
                prefix = ''
                if name[0] in self.priv_types:
                    prefix = name[0]
                    name = name[1:]
                if prefix == '~':
                    self.channels[channel]['USERS'][name] = \
                    ['~', '', '', '', '']
                elif prefix == '&':
                    self.channels[channel]['USERS'][name] = \
                    ['', '&', '', '', '']
                elif prefix == '@':
                    self.channels[channel]['USERS'][name] = \
                    ['', '', '@', '', '']
                elif prefix == '%':
                    self.channels[channel]['USERS'][name] = \
                    ['', '', '', '%', '']
                elif prefix == '+':
                    self.channels[channel]['USERS'][name] = \
                    ['', '', '', '', '+']
                else:
                    self.channels[channel]['USERS'][name] = \
                    ['', '', '', '', '']
            return names
960124
def channels_info(self, room_id=None, channel=None, **kwargs):
        """"""
        if room_id:
            return self.__call_api_get('channels.info', roomId=room_id, kwargs=kwargs)
        elif channel:
            return self.__call_api_get('channels.info', roomName=channel, kwargs=kwargs)
        else:
            raise RocketMissingParamException('roomId or channel required')
580049
def history(self, group_name, **kwargs):
        
        group_id = self.get_group_id(group_name)
        self.params.update({
            'channel': group_id,
            })
        if kwargs:
            self.params.update(kwargs)
        return FromUrl('https://slack.com/api/groups.history', self._requests)(data=self.params).get()
637099
function SlackRtmOut(n) {
    RED.nodes.createNode(this, n);

    var node = this;
    this.client = n.client;
    this.clientNode = RED.nodes.getNode(this.client);

    node.status(statuses.disconnected);

    if (node.client) {
      SetConfigNodeConnectionListeners(node);

      node.on("input", function(msg) {
        SlackDebug("slack-rtm-out incomiming message", msg);

        /**
         * message, presence_sub, presence_query, ping, and typing.
         */
        var method = msg.topic;
        var options = msg.payload;

        if (
          !method ||
          typeof method !== "string" ||
          !method instanceof String
        ) {
          node.error("invalid msg.topic");
          return null;
        }

        /**
         * Try to help with common use case, set channel based on lookup if starts with @ or #
         */
        if (
          method == "message" &&
          (options.channel[0] == "@" || options.channel[0] == "#")
        ) {
          var channel = node.clientNode.findChannelByName(options.channel);
          if (channel && channel.id) {
            options.channel = channel.id;
          }
        }

        /**
         * special handling for simple use-case
         */
        if (method[0] == "@" || method[0] == "#") {
          var channel = node.clientNode.findChannelByName(method);
          if (!channel || !channel.id) {
            node.error("invalid channel: " + method);
            return null;
          }
          method = "message";
          options = {
            text: msg.payload,
            channel: channel.id
          };
        }

        /**
         * custom per-method logic
         */
        switch (method) {
          case "message":
            // force text to be a string
            options.text = ValueToString(options.text);
            break;
        }

        /**
         * something seems to block when it's not message events
         * keeping a hard-coded list for now until the 'bug' is squashed
         *
         * https://github.com/slackapi/node-slack-sdk/issues/706
         *
         * There's only 5 (public) writable events on RTM: message,
         * presence_sub, presence_query, ping, and typing.
         *
         * The only two that expect responses are message and ping.
         */
        var awaitReply = false;
        switch (method) {
          case "message":
          case "ping":
            awaitReply = true;
            break;
          case "presence_sub":
          case "presence_query":
          case "typing":
            awaitReply = false;
            break;
          default:
            /**
             * go ahead and let invalid methods await so a negative/error
             * response is returned
             */
            awaitReply = true;
            break;
        }

        node.status(statuses.sending);
        msg.slackState = node.clientNode.state;

        SlackDebug("slack-rtm-out call", method, options);
        node.clientNode.rtmClient
          .addOutgoingEvent(awaitReply, method, options)
          .then(res => {
            /**
             * mock a response for methods which return nothing
             * ie: everything but message and ping
             */
            if (typeof res === "undefined") {
              res = {
                ok: true,
                type: method
              };
            }

            SlackDebug("slack-rtm-out call response", res);
            msg.payload = res;
            node.send(msg);
            node.status(statuses.connected);
          })
          .catch(e => {
            SlackDebug("slack-rtm-out error response", e.data);
            msg.payload = e.data;
            node.send(msg);
            node.status(statuses.connected);
          });
      });
    } else {
      node.status(statuses.misconfigured);
    }
  }
366721
def subscribers(self):
        """"""
        return [s for p, s in sorted(self._subscribers, key=lambda x: x[0])]
319649
def mark(self, channel_name, ts):
        
        channel_id = self.get_channel_id(channel_name)
        self.params.update({
            'channel':  channel_id,
            'ts':       ts,
            })
        return FromUrl('https://slack.com/api/channels.mark', self._requests)(data=self.params).post()
196898
def notify(self, data):
        """"""
        triggered_channels = []
        for channel_name, items in data.items():
            for item in items or []:
                LOG.debug('notify received: %s', item)
                try:
                    # some channels return strings rather than objects (e.g. de-registrations),
                    # normalize them here
                    item = {'value': item} if isinstance(item, six.string_types) else dict(item)
                    # inject the channel name to the data (so channels can filter on it)
                    item['channel'] = channel_name
                    triggered_channels.extend(list(self._notify_single_item(item)))
                except Exception:  # noqa
                    LOG.exception('Subscription notification failed')
        return triggered_channels
486337
def invite(self, group_name, user):
        
        group_id = self.get_group_id(group_name)
        self.params.update({
            'channel': group_id,
            'user':    user,
            })
        return FromUrl('https://slack.com/api/groups.invite', self._requests)(data=self.params)
341215
def Channels(module):
    '''
    

    '''

    nums = {2: 1, 3: 5, 4: 9, 6: 13, 7: 17, 8: 21, 9: 25,
            10: 29, 11: 33, 12: 37, 13: 41, 14: 45, 15: 49,
            16: 53, 17: 57, 18: 61, 19: 65, 20: 69, 22: 73,
            23: 77, 24: 81}

    if module in nums:
        return [nums[module], nums[module] + 1,
                nums[module] + 2, nums[module] + 3]
    else:
        return None
25889
def get_channels(self):
        
        selectedItems = self.idx_chan.selectedItems()
        selected_chan = [x.text() for x in selectedItems]
        chan_in_order = []
        for chan in self.chan:
            if chan in selected_chan:
                chan_in_order.append(chan)

        return chan_in_order
359017
private void getImChannels(String slackToken, int limit, String nextCursor) {
        try {
            Event event = restTemplate.getForEntity(slackApiEndpoints.getImListApi(), Event.class,
                    slackToken, limit, nextCursor).getBody();
            imChannelIds.addAll(Arrays.stream(event.getIms()).map(Channel::getId).collect(Collectors.toList()));
            if (event.getResponseMetadata() != null &&
                    !StringUtils.isEmpty(event.getResponseMetadata().getNextCursor())) {
                Thread.sleep(5000L); // sleep because its a tier 2 api which allows only 20 calls per minute
                getImChannels(slackToken, limit, event.getResponseMetadata().getNextCursor());
            }
        } catch (Exception e) {
            logger.error("Error fetching im channels for the bot: ", e);
        }
    }
442994
def list_(self):
        
        with self.lock:
            self.send('LIST')
            list_ = {}

            while self.readable():
                msg = self._recv(expected_replies=('322', '321', '323'))

                if msg[0] == '322':
                    channel, usercount, modes, topic = msg[2].split(' ', 3)
                    modes = modes.replace(':', '', 1).replace(':', '', 1)
                    modes = modes.replace('[', '').replace( \
                                                    ']', '').replace('+', '')
                    list_[channel] = usercount, modes, topic
                elif msg[0] == '321':
                    pass
                elif msg[0] == '323':
                    break

            return list_
1026682
def channels_invite(self, room_id, user_id, **kwargs):
        """"""
        return self.__call_api_post('channels.invite', roomId=room_id, userId=user_id, kwargs=kwargs)
291610
def kick(self, group_name, user):
        
        group_id = self.get_group_id(group_name)
        self.params.update({
            'channel': group_id,
            'user':    user,
            })
        return FromUrl('https://slack.com/api/groups.kick', self._requests)(data=self.params).post()