Joins a new channel.

        Keyword arguments:
        new_channel: <str>; the channel to connect to
        nick: <str>; the nickname to use
        pwd: <str>; the (optional) password to use
513727
def join(self, new_channel, nick, pwd=None):
        
        self._send_packet({"cmd": "join", "channel": new_channel,
                           "nick": self._format_nick(nick, pwd)})
1107038
def save_new_channel(self):
        
        form_info = self.input['form']
        channel = Channel(typ=15, name=form_info['name'],
                          description=form_info['description'],
                          owner_id=form_info['owner_id'])
        channel.blocking_save()
        self.current.task_data['target_channel_key'] = channel.key
82579
def join_channel(self, channel):
        
        self.s.send(('JOIN #%s\r\n' % channel).encode('utf-8'))
        if self.verbose:
            print('JOIN #%s\r\n' % channel)
704545
def construct_channel(self, **kwargs):
        
        channel = self.get_channel(**kwargs)
        json_tree_path = self.get_json_tree_path(**kwargs)
        json_tree = read_tree_from_json(json_tree_path)
        build_tree_from_json(channel, json_tree['children'])
        raise_for_invalid_channel(channel)
        return channel
304388
def _new_conn(self):
        
        extra_kw = {}
        if self.source_address:
            extra_kw['source_address'] = self.source_address

        if self.socket_options:
            extra_kw['socket_options'] = self.socket_options

        try:
            conn = socks.create_connection(
                (self.host, self.port),
                proxy_type=self._socks_options['socks_version'],
                proxy_addr=self._socks_options['proxy_host'],
                proxy_port=self._socks_options['proxy_port'],
                proxy_username=self._socks_options['username'],
                proxy_password=self._socks_options['password'],
                proxy_rdns=self._socks_options['rdns'],
                timeout=self.timeout,
                **extra_kw
            )

        except SocketTimeout as e:
            raise ConnectTimeoutError(
                self, "Connection to %s timed out. (connect timeout=%s)" %
                (self.host, self.timeout))

        except socks.ProxyError as e:
            # This is fragile as hell, but it seems to be the only way to raise
            # useful errors here.
            if e.socket_err:
                error = e.socket_err
                if isinstance(error, SocketTimeout):
                    raise ConnectTimeoutError(
                        self,
                        "Connection to %s timed out. (connect timeout=%s)" %
                        (self.host, self.timeout)
                    )
                else:
                    raise NewConnectionError(
                        self,
                        "Failed to establish a new connection: %s" % error
                    )
            else:
                raise NewConnectionError(
                    self,
                    "Failed to establish a new connection: %s" % e
                )

        except SocketError as e:  # Defensive: PySocks should catch all these.
            raise NewConnectionError(
                self, "Failed to establish a new connection: %s" % e)

        return conn
939605
def open_channel(self):
        
        self._logger.debug('Creating a new channel')
        self._connection.channel(on_open_callback=self.on_channel_open)
1254895
async def _connect(self, hostname, port, reconnect=False, password=None, encoding=pydle.protocol.DEFAULT_ENCODING, channels=[], tls=False, tls_verify=False, source_address=None):
        
        self.password = password

        # Create connection if we can't reuse it.
        if not reconnect:
            self._autojoin_channels = channels
            self.connection = connection.Connection(hostname, port,
                source_address=source_address,
                tls=tls, tls_verify=tls_verify,
                tls_certificate_file=self.tls_client_cert,
                tls_certificate_keyfile=self.tls_client_cert_key,
                tls_certificate_password=self.tls_client_cert_password,
                eventloop=self.eventloop)
            self.encoding = encoding

        # Connect.
        await self.connection.connect()
1243979
def cmd(send, msg, args):
    
    parser = arguments.ArgParser(args['config'])
    parser.add_argument('--channel', action=arguments.ChanParser)
    parser.add_argument('nick', nargs='*')
    try:
        cmdargs = parser.parse_args(msg)
    except arguments.ArgumentException as e:
        send(str(e))
        return
    quote = args['db'].query(Log.msg, Log.source)
    nick = ' '.join(cmdargs.nick) if cmdargs.nick else ""
    if nick:
        quote = quote.filter(Log.source == nick)
    else:
        quote = quote.filter(Log.source != args['botnick'])
    target = cmdargs.channels[0] if hasattr(cmdargs, 'channels') else args['config']['core']['channel']
    quote = quote.filter(or_(Log.type == 'pubmsg', Log.type == 'privmsg', Log.type == 'action'), Log.target == target,
                         func.length(Log.msg) > 5).order_by(func.random()).first()
    if quote:
        send("%s -- %s" % quote)
    elif nick:
        send("%s isn't very quotable." % nick)
    else:
        send("Nobody is very quotable :(")
1164760
def on_connect(self, connection):
        ""
        # NOTE: for python3, we can't pass bytestrings as keyword arguments
        # so we need to decode channel/pattern names back to unicode strings
        # before passing them to [p]subscribe.
        self.pending_unsubscribe_channels.clear()
        self.pending_unsubscribe_patterns.clear()
        if self.channels:
            channels = {}
            for k, v in iteritems(self.channels):
                channels[self.encoder.decode(k, force=True)] = v
            self.subscribe(**channels)
        if self.patterns:
            patterns = {}
            for k, v in iteritems(self.patterns):
                patterns[self.encoder.decode(k, force=True)] = v
            self.psubscribe(**patterns)
325775
def add_user(self, user):
        """"""
        if not isinstance(user, User):
            user = User(user)
        if user.nick in self.members:
            _log.warning("Ignoring request to add user '%s' to channel '%s' "
                         "because that user is already in the member list.",
                         user, self.name)
            return
        self.members[user.nick] = user
        _log.debug("Added '%s' to channel '%s'", user, self.name)
661214
def choose_existing_channel(self):
        

        if self.current.task_data.get('msg', False):
            self.show_warning_messages()

        _form = ChannelListForm()
        _form.title = _(u"Choose a Channel Which Will Be Merged With Chosen Channels")

        for channel in Channel.objects.filter(typ=15).exclude(
                key__in=self.current.task_data['chosen_channels']):
            owner_name = channel.owner.username
            _form.ChannelList(choice=False, name=channel.name, owner=owner_name,
                              key=channel.key)

        _form.choose = fields.Button(_(u"Choose"))
        self.form_out(_form)
708151
def add_to_channel(env, blueprint_name, id, channel)
      raise "'env' must be a String or an Environment." \
        unless env.is_a?(String) || env.is_a?(Environments::Environment)
      raise "'blueprint_name' must be a String." unless blueprint_name.is_a?(String)
      raise "'id' must be a Fixnum." unless id.is_a?(Fixnum)
      raise "'channel' must be a String or Symbol." \
        unless channel.is_a?(String) || channel.is_a?(Symbol)

      if env.is_a?(String)
        env = environment(env)
      end

      raise "channel '#{channel}' does not exist in environment '#{env.name}'." \
        unless env.channels.key?(channel.to_s) || channel.to_sym == :latest

      credentials = Amigrind::Config.aws_credentials(env)

      amigrind_client = Amigrind::Core::Client.new(env.aws.region, credentials)
      ec2 = Aws::EC2::Client.new(region: env.aws.region, credentials: credentials)

      image = amigrind_client.get_image_by_id(name: blueprint_name, id: id)

      tag_key = Amigrind::Core::AMIGRIND_CHANNEL_TAG % { channel_name: channel }

      info_log "setting '#{tag_key}' on image #{image.id}..."
      ec2.create_tags(
        resources: [ image.id ],
        tags: [
          {
            key: tag_key,
            value: '1'
          }
        ]
      )
    end
238100
def channels_set_join_code(self, room_id, join_code, **kwargs):
        """"""
        return self.__call_api_post('channels.setJoinCode', roomId=room_id, joinCode=join_code, kwargs=kwargs)
120054
def rename(self, channel_name, new_name):
        
        channel_id = self.get_channel_id(channel_name)
        self.params.update({
            'channel':  channel_id,
            'name':     new_name,
            })
        return FromUrl('https://slack.com/api/channels.rename', self._requests)(data=self.params).post()
926368
def add_channel(self, channel, pwd_hash):
        
        if channel.pwd_hash == pwd_hash:
            self.channels.append(channel)
            lg.record_process('comms.py', 'Added channel ' + channel.name)

            return True
        else:
            lg.record_process('comms.py', 'ERROR - Cant add channel : wrong hash for ' + channel.name)
            return False
863975
def _connect(self):
        
        self.conn = self._create_connection()
        spawn(self.conn.connect)
        self.set_nick(self.nick)
        self.cmd(u'USER', u'{0} 3 * {1}'.format(self.nick, self.realname))
792097
def create_channel(n = nil, _pool_size = 1, *_args)
      # raise same error as {Bunny::Session#create_channel}
      raise ArgumentError, 'channel number 0 is reserved in the protocol and cannot be used' if n && n.zero?

      # return cached channel if exists
      return @channels[n] if n && @channels.key?(n)

      # create and open channel
      channel = Channel.new self, n
      channel.open

      # return channel
      @channels[n] = channel
    end